29 lines
815 B
TypeScript
29 lines
815 B
TypeScript
import type { MarkdownConfig } from '@lezer/markdown';
|
|
import { styleTags, Tag, tags } from '@lezer/highlight';
|
|
|
|
export const tagTag = Tag.define('tag');
|
|
export const tag: MarkdownConfig = {
|
|
defineNodes: [
|
|
'Tag',
|
|
'TagMeta',
|
|
],
|
|
parseInline: [{
|
|
name: 'Tag',
|
|
after: 'Wikilink',
|
|
parse(cx, next, pos)
|
|
{
|
|
//35 == '#'
|
|
if (cx.slice(pos, pos + 1).charCodeAt(0) !== 35 || String.fromCharCode(next).trim() === '') return -1;
|
|
if(pos !== 0 && cx.slice(pos - 1, pos).match(/\w/)) return -1;
|
|
|
|
const end = cx.slice(pos, cx.end).search(/\s/);
|
|
return cx.addElement(cx.elt('Tag', pos, end === -1 ? cx.end : pos + end));
|
|
},
|
|
}],
|
|
props: [
|
|
styleTags({
|
|
'Tag': tagTag,
|
|
})
|
|
]
|
|
};
|