marked
marked copied to clipboard
Extension not triggering
Marked version:
Describe the bug
I have created an extension to try and detect runs of newlines but neither source
function nor tokenizer
function ever seem to get called.
I am using like:
export class Markdown {
#marked = new Marked().use({
extensions: [newlineExtension]
});
// other stuff in my class
}
To Reproduce
- Define your extension as follows:
export const newlineExtension: TokenizerExtension = {
name: 'newline',
level: 'block',
start(src) {
return src.match(/[\n]/)?.index
},
tokenizer(src, tokens) {
const match = src.match(/^[\n]{2,}$/);
if (match && match.length > 0) {
return {
type: 'newline',
raw: match[0]
}
}
return undefined;
}
};
- Pass your extension on to marked:
export class Markdown {
#marked = new Marked().use({
extensions: [newlineExtension]
});
// other stuff in my class
}
- Pass the following string in:
const multiLine = `
First line
Second line
`
In this case I am still getting space
with raw: '\n\n\n\n\n\n\n'
as the token type.
Expected behavior
I would expect my extension function(s) to get called a single newline
token to get created