javascript - RegExp working in JSFiddle but not in nodejs -
i have regular expression:
/(?:!!)(.+)(?:!!)(?:\(zoomon )([\s,]+)(?:\))/g
it matches !!some text!!(zoomon 1,2,3)
.
this works okay in browser (jsfiddle here) not in node. writing in es2015, using babel , es2015 preset.
for insight showdown extension. noticed twitter extension add \
regexps. quirk of node/es5 i'm not aware of?
update
i hoping wouldn't need post code node since thought node quirk.
anyway, code extension showdown:
# extensions.js export const manipulationapiextensions = () => [ { // [zoomon node1,node2,node3,...](some text) type: 'lang', filter: (text, converter, options) => { const toreturn = text.replace(/(?:!!)(.+)(?:!!)(?:\(zoomon )([\s,]+)(?:\))/g, (match, innertext, nodestring) => { const nodes = nodestring.split(/\s*,\s*/); let nodearrayasstring = '['; nodes.foreach(node => { nodearrayasstring += `'${node}',`; }); nodearrayasstring += ']'; return `<a onclick="pathwayinstance.manipulator.zoomon(${nodearrayasstring})">${text}</a>`; }); return toreturn; }, }, ];
this used in showdown follows:
export const getshowdown = (kaavioinstance) => { window.diagram = kaavioinstance; showdown.extension('kaavio', manipulationapiextensions()); return new showdown.converter({ extensions: ['kaavio'], }); };
and in unit test:
describe('custommarkdown', () => { // don't need kaavio since checking output html const mockkaavioinstance = {}; const converter = getshowdown(mockkaavioinstance); console.log(converter.getallextensions()) describe('kaavio', () => { it('should return correct html markdown', () => { const markdown = normalize(fs.readfilesync(`${__dirname}/extensions/kaavio.md`, 'utf8')); const html = normalize(fs.readfilesync(`${__dirname}/extensions/kaavio.html`, 'utf8')); const output = converter.makehtml(markdown); assert.equal(output, html); }); }); });
the unit test fails since no match found.
if simple below works. of course unit test doesn't work if console.log out expected result of matched
.
# extensions.js export const manipulationapiextensions = () => [ { // [zoomon node1,node2,node3,...](some text) type: 'lang', filter: (text, converter, options) => { const toreturn = text.replace(/./g, (match) => { return 'matched'; }); return toreturn; }, }, ];
that works me in node, tried it, fiddle uses alert(). need use console.log() node understands.
var text = '!!some text!!(zoomon node1)'; text.replace(/(?:!!)(.+)(?:!!)(?:\(zoomon )([\s,]+)(?:\))/g, function (match, innertext, nodestring) { console.log("matched!"); })
maybe have other code didn't post interfering?
Comments
Post a Comment