Prism: [Enhancement] Readjust few new tokens for HTML

Created on 29 Apr 2020  路  15Comments  路  Source: PrismJS/prism

Hello @Golmote, @RunDevelopment, @mAAdhaTTah and @zeitgeist87!

Description

In reference to https://github.com/dracula/prism/issues/11, I followed the Dracula's specific documentation. Imitating and mimicking the HTML syntax highlighting in VSCode, there are small differences between Prism's HTML and VSCode's HTML syntax highlightings. See the alternatives with solutions:

Alternatives

  1. Using Dracula theme, compare <!DOCTYPE html>, entirely highlighted as pink by the class token.doctype in Prismjs, but in VSCode, it is different:

    prismjs

    vscode

    Solution:

    • You should maintain the class token.doctype, which will regex the whole <!DOCTYPE html>, but;
    • You should create the new class token.doctype-name which will regex DOCTYPE or doctype;
    • You should create the new class token.doctype-html which will regex html.
  2. Observe the same images, you can see the different colour of = (equal symbol) and of quotation marks, which belong to the class token.punctuation, of which brackets and parentheses also make part. But to get the same result, you should separate the equal symbol and the quotation marks from the token.punctuation only if you add language-html, language-markup and language-php.

    Solution:

    • Create the new class language-xxx (html, markup and php) token.punctuation-equal for equal symbol;
    • Create the new class language-xxx (html, markup and php) token.punctuation-quotes for quotation marks.
  3. Using the Dracula theme ASCII codes are highlighted as pink, and declared by the class .token.entity by Prismjs, while Dracula's specific documentation鈥檚 HtmlTags declares the colour as purple, as we see in VSCode. If I change the colour to purple, all the entities also will become purple, the ASCII codes should be separated from the classes, the entities and the functions.

    prismjs

    vscode

    Solution:

    • Separate the ASCII codes (beginning with & and &# and ending with ;) from the entities and create the new class token.ascii.
enhancement

All 15 comments

I implemented most of your suggestions and you should now be able to implement the theme.
Some notes:

  1. I called DOCTYPE .doctype-tag to be more consistent with other tags. html is called .name because it's really just a name and nothing special. See the XML spec on doctype for more info.
  2. I only implemented .punctuation-equal but as .attr-equal to be more consistent with .attr-name and .attr-value. Since you can now properly distinguish = for other punctuation, you can still implement special highlighting for quotes, so I hope that's alright.
  3. I added an alias for named entities (.named-entity) because I think that's more descriptive than .ascii. I also went for an alias because it is compatible with the entity plugin markup has (when you hover over an .entity token, the encoded character will be displayed).

I hope it still works for even with the changes I made.

Great, @RunDevelopment! I'll clone, compile and test it.

@RunDevelopment

I cloned your repository RunDevelopment/prism. For days, I tried to merge and compile, but your different three branches merged into one branch never worked and always gave errors.

Yes, merging them won't work. prism-markup.min.js will cause conflicts. It's easy to resolve because all .min.js files are generated, so the conflict is resolved by regenerating them using our build system.
Well, it's easy once you know about the build system and which files you can basically ignore during a merge conflict. Maybe I should add that to the readme.

Here's a branch which has the changes of all 3.

Hello @RunDevelopment !

Thank you for creating the branch and merging all the branches. I git-pulled the upstream.

I copied the latest prism.js. I have just tested, but only named-entity does not work, because it does not appear in the compiled HTML file even if named-entity is already present in the file prism.js:

image

My CSS was:

.token.entity 
{
  color: var(--pink);
}

.token.entity.named-entity 
{
  color: var(--purple);
}

.language-html .token.entity 
{
  color: var(--pink);
}

.language-html .token.entity.named-entity 
{
  color: var(--purple);
}

That's because &#035; doesn't have a name. &amp; and &lt; are examples of named entities.

That's because &#035; doesn't have a name. &amp; and &lt; are examples of named entities.

Maybe we need to create a new alias?

Why?
From what I see, there are two kinds of entities: named ones (e.g. &amp;) and unnamed ones (e.g. &#65; and &#x41;). You can differentiate them by the presence of the .named-entity alias. So why do we need a new alias?

Why?

Because, to mimic the VSCode theme, and following Dracula's documentation, the unnamed entities have to be purple instead of pink.

So like this?

image
image
(Sorry for the bad contrast)

Hello @RunDevelopment !

Yes, it is. Both they have to be pink. Actually they have to be purple because, in Dracula-themed VSCode, both named and unnamed entities are purple.

I need to see if .token.entity, which I would set to Dracula's purple colour, also will affect the entities in other languages, which need to remain pink.

So the normal color of all entities is pink and only the unnamed entities in markup are purple?
Like this:

.token.entity {
  color: pink;
}
.language-markup .token.entity:not(.named-entity) {
  color: purple;
}

Hello @RunDevelopment

You figured and got it. Thank you! I'm going to test it.

Hello @RunDevelopment

With your pull request merged, the colours do not work anymore:

image

It seems that the site of Prismjs did not update the developer file.

Sorry, it worked now, because you used markup instead of html.

image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sheljohn picture sheljohn  路  4Comments

timgoeller picture timgoeller  路  4Comments

RunDevelopment picture RunDevelopment  路  5Comments

timehat picture timehat  路  4Comments

brian-kephart picture brian-kephart  路  6Comments