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

Consider sanitizing HTML tags from TOC entries #24

Closed
jayv opened this issue Dec 9, 2023 · 3 comments
Closed

Consider sanitizing HTML tags from TOC entries #24

jayv opened this issue Dec 9, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@jayv
Copy link

jayv commented Dec 9, 2023

Some plugins, eg. Highlightr plugin inject markup via HTML tags which messes up the TOC:

image

It would be nice if the plugin could strip any HTML tags, a simple regex <(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+> replace to '' might do it.

Example payload:
<mark style="background: #FFF3A3A6;">Some title</mark>

Preserving the markup as opposed to escaping it would also be nice, but is more a nice to have.

@AV-AER
Copy link

AV-AER commented Dec 22, 2023

Been having the same problem for a while now, so thanks for opening this issue.
Currently working on a fork for this, your regex is very helpful in this.
Also trying to squeeze in a fix for headings with internal links already in them.

If you do not use the clickable links option in aTOC, you can quite easily skip over the whole headache of sanitizing the headers for HTML. But it still causes a headache for other reasons and having clickable headers is part of the reason why I even use the plugin to begin with.

Hoping to have a somewhat fixed fork ready this week.

@AV-AER
Copy link

AV-AER commented Dec 23, 2023

Finally finished the first revision of this.

When it comes to stripping HTML tags, I've made it completely optional.
I've also added an option to enable/disable Markdown links: [text](https://github.com/).
Both these options/rules are overridden by the pre-existing includeLinks option.

Small overview of the new options:

allowStyleHTML: {
    type: 'boolean',
    default: false,
    comment: 'When includeLinks is false, allows HTML styling for headings',
  },
  includeMarkdownLinks: {
    type: 'boolean',
    default: true,
    comment: 'When includeLinks is false, allows Markdown links in headings',
  },

I'm not quite sure what the "standard behaviour" should be when includeLinks is disabled.

(Also the first revision is seriously buggy and full of unnecessary code. PR comes when I get enough time to clean it up a smidge.)

Edit: (24.12.23) added one more option:

showMarkdownLinksInLinks: {
    type: 'boolean',
    default: false,
    comment: 'Allows Markdown links in headings when links are also enabled.',
  },

Also still cleaning up the code.

@johansatge johansatge added the bug Something isn't working label Jan 19, 2024
@johansatge
Copy link
Owner

Hello! HTML is now stripped in 1.3.1

Unfortunately I couldn't find a way to keep the formatting without impacting other features

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants