Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lib changeItems #2

Merged
merged 3 commits into from
Apr 28, 2020
Merged

Lib changeItems #2

merged 3 commits into from
Apr 28, 2020

Conversation

guesant
Copy link
Owner

@guesant guesant commented Apr 28, 2020

New libs:

  • changeItemsByHTML

    changeItemsByHTML({
      html: "<p><!-- your html code --></p>",
      selector: 'p',
      changeItem: (node: Node) => {
        node.atttribs.class = "foo";
        return (domutils).getOuterHTML(node);
      }
    })

    Output: <p class="foo"><!-- your html code --></p>

  • changeItemsByHTMLFallback

    changeItemsByHTMLFallback({
      html: sergeyLibs.prepareHTML('<a title="<get-title />">text</a>'),
      selector: 'a',
      changeItem: (node: Node) => {
        return "Awesome link!";
      }
    })

    Output: <a title="Awesome link!">text</a>

guesant added 3 commits April 28, 2020 08:12
```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
@guesant guesant merged commit 60827f1 into smart-tag-query Apr 28, 2020
@guesant guesant deleted the lib-change-items branch April 28, 2020 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant