initial commits

master
Charles Iliya Krempeaux 2023-11-15 16:05:06 -08:00
parent 0f9ec01005
commit 811f246ad3
2 changed files with 24 additions and 3 deletions

20
ziba.js
View File

@ -20,26 +20,38 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
export function transform(rootElement) {
console.log("[ziba][transform] begin")
if (undefined === rootElement) {
console.log("[ziba][transform] root-elelemt is undefined")
console.log("[ziba][transform] end")
return
}
transform_link(rootElement)
console.log("[ziba][transform] end")
}
function transform_link(rootElement) {
console.log("[ziba][transform_link] begin")
if (undefined === rootElement) {
console.log("[ziba] root-elelemt is undefined")
console.log("[ziba][transform_link] root-elelemt is undefined")
console.log("[ziba][transform_link] end")
return
}
const tagName = "ziba-link"
const elements = rootElement.getElementsByTagName(tagName)
if (!elements) {
console.log("[ziba] no elements")
console.log("[ziba] rootElement.innerHTML=", rootElement.innerHTML)
console.log("[ziba][transform_link] no elements")
console.log("[ziba][transform_link] rootElement.innerHTML=", rootElement.innerHTML)
console.log("[ziba][transform_link] end")
return
}
const length = elements.length
console.log("[ziba][transform_link] found", length, tagName)
// Because we are doing a replaceWith() on the HTMLCollection,
// we need to iterate through it backwards, because the HTMLCollection
@ -65,4 +77,6 @@ function transform_link(rootElement) {
element.replaceWith(anchor)
}
console.log("[ziba][transform_link] end")
}

View File

@ -66,6 +66,13 @@ function testTransform() {
html:'<ziba-link title="1 2 3 4">ONCE TWICE THRICE FOURCE</ziba-link>',
expected:'<a href="./1 2 3 4">ONCE TWICE THRICE FOURCE</a>',
},
{
html:'<ul><li><ziba-link>one</ziba-link></li><li><ziba-link>two</ziba-link></li><li><ziba-link>three</ziba-link></li></ul>',
expected:'<ul><li><a href="./one">one</a></li><li><a href="./two">two</a></li><li><a href="./three">three</a></li></ul>',
},
]