There is an error when trying to pass options as `parse` argument
Closed this issue · 3 comments
marioosh commented
let options: MarkedOptions = {isNoP: true};
Marked.setOptions(options);//is working but
Marked.parse("some intput", options)//provides to error:
TypeError: this.options.escape is not a function
Please report this to https://github.com/KostyaTretyak/marked-ts
at InlineLexer.output (http://localhost:8100/build/vendor.js:74738:56)
at Parser.parseText (http://localhost:8100/build/vendor.js:74372:33)
at Parser.tok (http://localhost:8100/build/vendor.js:74387:37)
at Parser.parse (http://localhost:8100/build/vendor.js:74345:25)
at Function.Parser.parse (http://localhost:8100/build/vendor.js:74338:23)
at Function.Marked.callParser (http://localhost:8100/build/vendor.js:50612:36)
at Function.Marked.parse (http://localhost:8100/build/vendor.js:50558:25)
at MarkedProvider.webpackJsonp.214.MarkedProvider.simpleMarked (http://localhost:8100/build/main.js:162:66)
....
KostyaTretyak commented
Marked.setOptions(options)
makes merge with default options.- Second parameter for
Marked.parse("some intput", options)
apply your options without merge with default options.
Try just:
let options: MarkedOptions = {isNoP: true};
Marked.setOptions(options);
Marked.parse("some intput");
marioosh commented
Agree, but I have two functions one with options second without, and have at the beginning of each call Marked.setOptions
. It would be better to make possible use temporary options only for parsing..
Btw. I workarounded it, but reported this issue as bug.
KostyaTretyak commented
@marioosh, you can get all default options when call new MarkedOptions
:
import { Marked, MarkedOptions } from 'marked-ts';
const options1 = new MarkedOptions;
options1.isNoP = true;
const html1 = Marked.parse("some intput", options1);
const options2 = new MarkedOptions;
options2.isNoP = false;
const html2 = Marked.parse("some intput", options2);
console.log(html1); // some intput
console.log(html2); // <p>some intput</p>