From 481ac3bb1769839dbfeade3c5084ab995d6bc5f8 Mon Sep 17 00:00:00 2001 From: Louis Poirier Date: Mon, 10 Jun 2024 04:54:31 +0200 Subject: [PATCH] Update Lexer section in USING_PRO.md (#3317) --- docs/USING_PRO.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/USING_PRO.md b/docs/USING_PRO.md index c4e1ddd8d2..c07f1d286d 100644 --- a/docs/USING_PRO.md +++ b/docs/USING_PRO.md @@ -565,8 +565,6 @@ The parser takes tokens as input and calls the renderer functions. You also have direct access to the lexer and parser if you so desire. The lexer and parser options are the same as passed to `marked.setOptions()` except they have to be full options objects, they don't get merged with the current or default options. - - ``` js const tokens = marked.lexer(markdown, options); console.log(marked.parser(tokens, options)); @@ -582,6 +580,11 @@ console.log(marked.Lexer.rules.block); // all block level rules console.log(marked.Lexer.rules.inline); // all inline level rules ``` +Note that the lexer can be used in two different ways: + +- `marked.lexer()`: this method tokenizes a string and returns its tokens. Subsequent calls to `lexer()` ignore any previous calls. +- `new marked.Lexer().lex()`: this instance tokenizes a string and returns its tokens along with any previous tokens. Subsequent calls to `lex()` accumulate tokens. + ``` bash $ node > require('marked').lexer('> I am using marked.')