isf-hack-night / reps-app

App to take location data and show districts/reps/actions etc.
GNU General Public License v3.0
1 stars 3 forks source link

Markdown parser for Amplify action text #18

Open margitZ opened 7 years ago

RS-Crawford commented 7 years ago

I solved this using two libraries, markdown and jsxfromhtml.

Markdown is being parsed to HTML by markdown, that HTML is being converted to JSX by jsxfromhtml and then is renderable within the ActionInfo component:

const callScript = <JSXfromHTML html={markdown.toHTML(callScriptMd)} />
const callBackground = <JSXfromHTML html={markdown.toHTML(callBackgroundMd)} />
rtrochet commented 7 years ago

Links in the call background markdown don't appear to be converted to HTML. I think the above solution is no longer in use?

Those of you with more coding experience might have a more efficient method, but this seems to work and could go in the ActionInfo component at line 22:

URL = "";
var link = "";
var pattern = /\[(.+?)\]\((.+?)\)/;
while (pattern.test(callBackgroundMd)) {
  link = pattern.exec(callBackgroundMd);
  callBackgroundMd = callBackgroundMd.replace(pattern, URL.concat('<a href="',link[2],'">',link[1],"</a>"));
}
margitZ commented 7 years ago

also applicable to parsing flexActions