This repository was archived by the owner on Apr 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Use CSS selector query-based instead of Regular Expressions #43
Open
guesant
wants to merge
18
commits into
trys:master
Choose a base branch
from
guesant:smart-changetag
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`<sergey-slot ...args />` -> `<sergey-slot ...args></sergey-slot>` the function ignores void elements like `<img />`
```js changeItemsByHTML({ html: '<p><!-- your html code --></p>', selector: 'p', changeItem: (node: Node) => { node.atttribs.class += "foo"; return (domutils).getOuterHTML(node); } }) ```
Extends `changeItemsByHTML`. Can match tags inside tags (e.g. `<meta foo="<sergey-slot></sergey-slot>">`) ```js changeItemsByHTMLFallback({ html: '<p><!-- your html code --></p>', selector: 'p', changeItem: (node: Node) => { node.atttribs.class += "foo"; return (domutils).getOuterHTML(node); } }) ```
Exports `main`, `changeItemsByHTML` and `changeItemsByHTMLFallback` The `main` function recives `options` used in `changeItemsByHTML+` and a callback function to change the selected node. Returns string
Lib changeItems
Apply changetag
Deployment has failed due to an internal error. (code: Contact our support with [email protected] for more information. |
a8b6b94
to
339a032
Compare
Fix twice changeItem execution
Preparse xml to avoid code multiline definition
Lib nodes
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Query and change HTML tags with CSS Selectors using the modules CSSselect, htmlparser2 and domutils. The sergey's source code uses a lot of
while
loops and Regular Expressions. This proposal can handle html tags by querying with CSSselect and making a DOM-based changes with domutils.Before was:
Now can be:
Some implemented functions:
html/prepare-html
Prepare and format HTML code to be used later.
For example, parse
<sergey-slot />
to<sergey-slot ...args></sergey-slot>
html/change-tag
changeItemsByHTML
Output:
<p class="foo"></p>
changeItemsByHTMLFallback
The same implementation of
changeItemsByHTML
but works with tags inside tags (e.g.<a title="<some-getter />">text</a>
)main
Applies
changeItemsByHTML
andchangeItemsByHTMLFallback
(runs oncechangeItem
for the selected nodes).Maybe related with #36 #24