Open rauschma opened 8 months ago
where, how?
Example “HTML, XML” at https://highlightjs.org/examples – search for “language-javascript”:
<pre class="theme-atom-one-dark shadow-3xl text-sm relative overflow-hidden max-w-full h-[400px] mb-6"><span class="hljs mb-0 p-4 block min-h-full overflow-auto"><code><span class="hljs-meta"><!DOCTYPE <span class="hljs-keyword">html</span>></span>
<span class="hljs-tag"><<span class="hljs-name">title</span>></span>Title<span class="hljs-tag"></<span class="hljs-name">title</span>></span>
<span class="hljs-tag"><<span class="hljs-name">style</span>></span><span class="language-css"><span class="hljs-selector-tag">body</span> {<span class="hljs-attribute">width</span>: <span class="hljs-number">500px</span>;}</span><span class="hljs-tag"></<span class="hljs-name">style</span>></span>
<span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"application/javascript"</span>></span><span class="language-javascript">
<span class="hljs-keyword">function</span> <span class="hljs-title function_">$init</span>(<span class="hljs-params"></span>) {<span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;}
</span><span class="hljs-tag"></<span class="hljs-name">script</span>></span>
<span class="hljs-tag"><<span class="hljs-name">body</span>></span>
<span class="hljs-tag"><<span class="hljs-name">p</span> <span class="hljs-attr">checked</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"title"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">'title'</span>></span>Title<span class="hljs-tag"></<span class="hljs-name">p</span>></span>
<span class="hljs-comment"><!-- here goes the rest of the page --></span>
<span class="hljs-tag"></<span class="hljs-name">body</span>></span></code></span><small class="bg-black/30 absolute top-0 right-0 uppercase font-bold text-xs rounded-bl-md px-2 py-1"><span class="sr-only">Language:</span>HTML, XML</small></pre>
Right that’s highlightjs but how are you using lowlight and where are you getting javascript
?
Can you post actual input and actual output and expected output?
const sourceCodeHtml = outdent`
<!DOCTYPE html>
<title>Title</title>
<style>body {width: 500px;}</style>
<script>
function $init() {return true;}
</script>
<body>
<p checked class="title" id='title'>Title</p>
<!-- here goes the rest of the page -->
</body>
`;
function logHastTree() {
const lowlight = createLowlight(common);
const tree = lowlight.highlight('html', sourceCodeHtml);
console.dir(tree, { depth: undefined });
}
Nested inside the output:
{
type: 'element',
tagName: 'span',
properties: { className: [ 'javascript' ] },
It’s not a problem for me but I thought that you might want to know about the difference.
I dunno. Maybe related to https://github.com/wooorm/lowlight/blob/c5dc24bfb4e082781dd1582920ee7ef415901d39/lib/index.js#L449-L454. I’d assume they’d pass it. I don’t know when hljs chooses to prefix things with language-
.
Right! It has to be about .__addSublanguage()
. I don’t know which approach better fits your needs (with or without the prefix “language-”).
I don’t really have opinions about what value is “correct”; a prefix might be nice; matching hljs is probably nice too.
I’m getting (e.g.):
But Highlight.js uses
language-javascript