Skip to content

(parser) Deprecate: tabReplace parser option  #2874

@joshgoebel

Description

@joshgoebel

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions