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 useBR #2559

Closed
3 tasks done
joshgoebel opened this issue May 15, 2020 · 3 comments
Closed
3 tasks done

(parser) Deprecate useBR #2559

joshgoebel opened this issue May 15, 2020 · 3 comments
Labels
Milestone

Comments

@joshgoebel
Copy link
Member

joshgoebel commented May 15, 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.

useBR is a messy one for me, so I'm picking on it first. I think it's obvious the "best/blessed" path for using HLJS is with pre/code tags... that gives you the best chance of preserving your code in markup without doing ugly things like inserting HTML line breaks in it in the first place. Those who really need to use a different element and need to do <BR> > \n translate can simply use a plugin to accomplish the same thing in the future.

  • v10.1 Deprecate useBR
  • Provide plugin?
  • v11 Remove useBR

Consider: You probably don't want a plugin at all and should consider just using CSS white-space: pre if you really need your code in tags other than <pre>.

Plugin:

  const brPlugin = {
    "before:highlightBlock": ({ block }) => {
      block.innerHTML = block.innerHTML.replace(/\n/g, '').replace(/<br[ /]*>/g, '\n');
    },
    "after:highlightBlock": ({ result }) => {
      result.value = result.value.replace(/\n/g, "<br>");
    }
  };

// how to use it
hljs.addPlugin(brPlugin);
@joshgoebel joshgoebel added enhancement An enhancement or new feature discuss/propose Proposal for a new feature/direction labels May 15, 2020
@joshgoebel joshgoebel added this to the 11.0 milestone May 15, 2020
@joshgoebel joshgoebel mentioned this issue May 16, 2020
25 tasks
@egor-rogov
Copy link
Collaborator

+1

@joshgoebel joshgoebel changed the title Propose: Remove useBR (parser) Deprecate useBR Oct 6, 2020
@joshgoebel joshgoebel added parser and removed discuss/propose Proposal for a new feature/direction enhancement An enhancement or new feature labels Oct 6, 2020
@joshgoebel
Copy link
Member Author

joshgoebel commented Oct 6, 2020

Those who really need to use a different element and need to do
> \n translate can...

This is not encouraged. pre/code is the blessed path for multi-line code blocks. Someone wanting to restore this functionality using plugins could look at before:highlightBlock and after:highlightBlock.

I've changed this issue to "deprecate" and am closing it with 980832e.

Removal is tracked in the v11 todolist.

@my-small-white
Copy link

58/5000
I used this library and found that the code block was in one line and could not be solved until I saw the community discussion and realized that the
problem was caused. Thank you very much for solving my problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants