Keep href value in link
See original GitHub issueIs it possibile with the current api to keep both the content and the href
value in the <a>
tag?
Example:
stripHtml(`<a href="https://twitter.com/loretparisi">twitter:loretparisi ø</a>`).result
"https://twitter.com/loretparisi twitter:loretparisi ø"
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Is an empty href valid? - html - Stack Overflow
The href attribute on a and area elements must have a value that is a valid URL potentially surrounded by spaces. A valid...
Read more >HTML A Href Attribute: A Quick And Simple Guide »
All Attributes of the anchor Element Defines the title of a link, which appears to the user as a tooltip. Specifies the linked...
Read more >The HTML a href Attribute Explained with Examples
The href attribute can be used to link to local files or files on the internet. The <a href> attribute is supported by...
Read more >HTML a href Attribute - W3Schools
The href attribute specifies the URL of the page the link goes to. If the href attribute is not present, the <a> tag...
Read more ><a>: The Anchor element - HTML: HyperText Markup Language
The <a> HTML element (or anchor element), with its href attribute, creates a hyperlink to web pages, files, email addresses, locations in ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@paulthemagno Let me explain. When we need to mark multiple amendments on string, we need a way to mark “delete from this index to this index”, or “delete from this to this but also insert this”. Solution — Ranges. It’s just array of arrays: [[0, 1], [3,4, “add”]] — means delete from index 0 to index 1; then replace slice between index 3 and 4 with “add”.
I suspect what is happening, since callback API is consistent, it had to serve something for “insert”, so it gives you an empty string, meaning: replace
[deleteFrom, deleteTo]
with empty string. If third element in a range array is missing,null
or an empty string, it’s the same — deletion.Conceptually, there’s no way to get
twitter:loretparisi ø
because program only processes the HTML tags, opening<a>
separately from</a>
…In theory, one way to “get”
twitter:loretparisi ø
tied to the tag pair would be to use a parser (like this), traverse (for example using this), push each tag location to let’s say same Ranges (using this), then apply them onto a string (using this). I’m doing exact same thing instristri
, https://www.npmjs.com/package/stristri — it’s also an HTML stripping tool but based off a tokenizer — 164 lines of code.But that above might be overkill, try the callback, replacing tag-by-tag.
It depends what you need to achieve, I can draw up more examples if it helps. Also, have a look at existing examples.
seems doable, using
opts.cb
: