mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-03-29 14:18:11 +00:00
proper highlights for weird def lists
This commit is contained in:
@@ -79,53 +79,52 @@ export function tokenizeCustomMarkdown(text) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- inline definition lists ---
|
const singleLineRegex = /^([^:\n]*\S)(\s*)(::)([^\n]*)$/dmy;
|
||||||
if(/::/.test(lineText)) {
|
|
||||||
if(/^:*$/.test(lineText) == true) {
|
const match = singleLineRegex.exec(lineText);
|
||||||
return; //if line only has colons, stops
|
|
||||||
|
if(match) {
|
||||||
|
const [full, term, spaces, colons, desc] = match;
|
||||||
|
|
||||||
|
let offset = 0;
|
||||||
|
|
||||||
|
tokens.push({
|
||||||
|
line : lineNumber,
|
||||||
|
type : customTags.definitionList,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Term
|
||||||
|
tokens.push({
|
||||||
|
line : lineNumber,
|
||||||
|
type : customTags.definitionTerm,
|
||||||
|
from : offset,
|
||||||
|
to : offset + term.length,
|
||||||
|
});
|
||||||
|
offset += term.length;
|
||||||
|
|
||||||
|
// Spaces before ::
|
||||||
|
if(spaces) {
|
||||||
|
offset += spaces.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
const singleLineRegex = /^([^:\n]*\S)\s*(::)([^\n]*)$/dmy;
|
// :: colons
|
||||||
|
tokens.push({
|
||||||
|
line : lineNumber,
|
||||||
|
type : customTags.definitionColon,
|
||||||
|
from : offset,
|
||||||
|
to : offset + colons.length,
|
||||||
|
});
|
||||||
|
offset += colons.length;
|
||||||
|
|
||||||
const match = singleLineRegex.exec(lineText);
|
// Definition
|
||||||
|
tokens.push({
|
||||||
|
line : lineNumber,
|
||||||
|
type : customTags.definitionDesc,
|
||||||
|
from : offset,
|
||||||
|
to : offset + desc.length,
|
||||||
|
});
|
||||||
|
|
||||||
if(match) {
|
return;
|
||||||
const [full, term, colons, desc] = match;
|
|
||||||
let offset = 0;
|
|
||||||
// Entire line as definitionList
|
|
||||||
tokens.push({
|
|
||||||
line : lineNumber,
|
|
||||||
type : customTags.definitionList,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Term
|
|
||||||
tokens.push({
|
|
||||||
line : lineNumber,
|
|
||||||
type : customTags.definitionTerm,
|
|
||||||
from : offset,
|
|
||||||
to : offset + term.length,
|
|
||||||
});
|
|
||||||
offset += term.length;
|
|
||||||
|
|
||||||
// ::
|
|
||||||
tokens.push({
|
|
||||||
line : lineNumber,
|
|
||||||
type : customTags.definitionColon,
|
|
||||||
from : offset,
|
|
||||||
to : offset + colons.length,
|
|
||||||
});
|
|
||||||
offset += colons.length;
|
|
||||||
|
|
||||||
// Definition
|
|
||||||
tokens.push({
|
|
||||||
line : lineNumber,
|
|
||||||
type : customTags.definitionDesc,
|
|
||||||
from : offset,
|
|
||||||
to : offset + desc.length,
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// multiline def list
|
// multiline def list
|
||||||
@@ -254,7 +253,6 @@ export function tokenizeCustomCSS(text) {
|
|||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(tags);
|
|
||||||
//assign classes to tags provided by lezer, not unlike the function above
|
//assign classes to tags provided by lezer, not unlike the function above
|
||||||
export const customHighlightStyle = HighlightStyle.define([
|
export const customHighlightStyle = HighlightStyle.define([
|
||||||
{ tag: tags.heading, class: 'cm-header' },
|
{ tag: tags.heading, class: 'cm-header' },
|
||||||
|
|||||||
Reference in New Issue
Block a user