diff --git a/README.md b/README.md index 44f4a64..106fa8f 100644 --- a/README.md +++ b/README.md @@ -32,14 +32,7 @@ Writing html will be more fun! ``` -``` - ||||| - ;;;;; - ;;;;; - ..;;;;;.. - ':::::' - ':' -``` +↓ ```html @@ -55,3 +48,22 @@ Writing html will be more fun! ``` + +## Usage + +There are two ways to initialize Writedown. + +```html + +``` + +or + +```html + +``` diff --git a/docs/sample.html b/docs/sample.html new file mode 100644 index 0000000..056b365 --- /dev/null +++ b/docs/sample.html @@ -0,0 +1,66 @@ + + + + + + + + Writedown + + + + +

Outside

+
+

Hello!

+ +
+ +

Inside

+
+

Hello!

+ +
+ + + + diff --git a/package.json b/package.json index 6497355..c1e8e81 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wdjs", - "version": "1.0.0", + "version": "1.1.0", "description": "writing html will be more fun!", "main": "writedown.js", "scripts": { diff --git a/wd.js b/wd.js new file mode 100644 index 0000000..8e112fe --- /dev/null +++ b/wd.js @@ -0,0 +1,23 @@ +export function init(param) { + const el = param instanceof HTMLElement ? param : document.querySelector(param); + el.querySelectorAll('*').forEach(node => { + if (node.hasAttributes()) { + let attrs = [], classes = [], id = null; + for (const attr of node.attributes) { + switch (attr.name[0]) { + case '.': + classes.push(...attr.name.substring(1).split('.')); + attrs.push(attr.name); + break; + case '#': + id = attr.name.substring(1); + attrs.push(attr.name); + break; + } + } + for (const a of attrs) { node.removeAttribute(a) } + if (classes.length) node.classList.add(...classes); + if (id) node.id = id; + } + }); +}