2

I am very new with programming (legal professional) and builing a legaltech app. Essentially, I need to be able to have a markdown file where a few variables are changeable from the frontend code which is in NEXT JS.

The markdown file will then be used for a backend code which I have figured out somehow. I want to be in a position where my Frontend variables are dynamically interacting with the markdown file.

I think turndown is a library that can potentially enable this. However, as a beginner, I don't know how to go about it as there isn't much content on it. I also explored CodeMirror but I am not sure how that would work with this.

Would really appreciate if someone can help with this or just refer to a project which I can explore to solve this. Been stuck for a few weeks with this.

shafee
  • 15,566
  • 3
  • 19
  • 47
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Apr 15 '23 at 06:13

1 Answers1

1

You can use a templating engine like Handlebars or Mustache to insert variables in markdown text from NEXT or React frontend code.

Here's an example using handlebars:

Install the handlebars library: npm install handlebars
Create a Handlebars template file, e.g. template.handlebars

# Hello {{name}}!

This is a message from {{sender}}.

Use Handlebars in your frontend code to render the template with the variables

import Handlebars from "handlebars";

const template = Handlebars.compile(markdownText);
const variables = { name: "John Doe", sender: "Jane Smith" };
const renderedMarkdown = template(variables);

This will replace the placeholders for {{name}} and {{sender}} in the template with the values from the variables object.

As needed, use the renderedMarkdown variable in your frontend code.

When the user submits the form, send the variables object to your backend code so that the markdown file can be updated with the new values.

The modified markdown file can then be converted to HTML using a library such as Turndown.

I hope this was helpful! Please let me know if you have any additional questions.

user21520830
  • 121
  • 4