Click to show TOC

Communications Engine

A Example of how the Communications Engine could be implemented. This is a JavaScript function that takes a markdown template and replaces placeholders like ```@name``` or ```@name.opt1``` with actual values fetched from an API:

 
 
     

This function uses a regular expression to find placeholders like ```@name``` or ```@name.opt1``` in the template. It then calls the provided API fetch function to get the corresponding value based on the placeholder. If a value is obtained from the API, the function replaces the placeholder in the template with the actual value.

Here's how you can use the function: To convert Markdown to HTML in JavaScript, you can use a library like "marked". Here's how you can use it along with the previously defined function to fill placeholders:

  1. First, install the "marked" library using npm or yarn:
npm install marked
const markdownTemplate = `
Hello \`\`\`@name\`\`\`,

This is some content with an option: \`\`\`@name.opt1\`\`\`.

Thank you!
`;

The "marked" library's marked function is used to convert the filled markdown template into HTML. The resulting HTML content will be a rendered version of your filled t emplate, with placeholders replaced by values and the markdown syntax converted to HTML elements.




Page - 1




Some Helper Functions

Some data to play with, somethis the api might fetch

 
 
     
 
 
     

Replace the placeholder values in the apiFetchFunction with your actual API logic to fetch values. The function fillMarkdownTemplate will return a filled template with placeholders replaced by their corresponding values fetched from the API.

 
 
     




Page - 2




An Interface

Here's an example of an HTML form with a text area for entering a Markdown template and a button to generate the final message.json The code has also the handler that looks for change (due to editing) and genrates message every time a change is detected. In order to be more responsive, the handler waits for 300ms for more changes until finally generating output.

 
 
     
Markdown Template Generator


Output Doc



In this example, we've created a simple HTML form with a text area to input the Markdown template and a button to trigger the genMessage function. When the button is clicked, the genMessage function will read the content of the text area, call the fillMarkdownTemplate function to fill the placeholders, and then convert the filled template to HTML using the "marked" library. The HTML output will be displayed in a

with the id "output".

Remember to adjust the code according to your needs, especially the fillMarkdownTemplate and apiFetchFunction functions based on your requirements and data sources.




Page - 3