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

(parser) Deprecate: tabReplace parser option #2874

Closed
1 of 3 tasks
joshgoebel opened this issue Nov 17, 2020 · 0 comments · Fixed by #2873
Closed
1 of 3 tasks

(parser) Deprecate: tabReplace parser option #2874

joshgoebel opened this issue Nov 17, 2020 · 0 comments · Fixed by #2873
Labels
enhancement An enhancement or new feature parser
Milestone

Comments

@joshgoebel
Copy link
Member

joshgoebel commented Nov 17, 2020

From isagalaev in #2529:

I was walking by, and while I didn't read through the entire thing I wanted to say this. There were a few features added to the core at users' requests when it was all small an nimble. These days I would say it makes much more sense to be opinionated and remove corner cases like useBR, tabWidth and several different spellings of "lang-", "language-" as language prefixes in the class name (as far as I remember there is a very precise recommendation in HTML5 to use "language-"). Everyone with special cases would be expected to do pre- or post-processing.

Very early on we were perhaps a bit too open and allowed some things to slip into core that perhaps should not have - and today they are also things that could easily be handled with our new plugin API.

  • v10.5 Deprecate tabReplace
  • Provide plugin?
  • v11 Remove tabReplace

Plugin Code

Consider: Before resorting to this you should probably consider the much simpler CSS tab-size property.

const TAB_REPLACE_RE = /^(<[^>]+>|\t)+/gm;
const tabReplacePlugin = {
  "after:highlightBlock": ({ result }) => {
    result.value = result.value.replace(TAB_REPLACE_RE, (m) =>
      m.replace(/\t/g, options.tabReplace)
    );
  }
};

// how to use it
hljs.addPlugin(tabReplacePlugin);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature parser
Projects
None yet
1 participant