improve example in update-code-from-shorthand

This commit is contained in:
jhauga 2025-11-02 15:32:31 -05:00
parent 002cbc3607
commit 9f9b4bbb84

View File

@ -94,7 +94,9 @@ solution for the goal.
```bash ```bash
[user prompt] [user prompt]
UPDATE CODE FROM SHORTHAND UPDATE CODE FROM SHORTHAND
script.js #file:script.js
Use #file:index.html:94-99 to see where converted
markdown to html will be parsed `id="a"`.
``` ```
### Code File ### Code File
@ -108,8 +110,18 @@ var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() { xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) { if (this.readyState == 4 && this.status == 200) {
let data = this.responseText; let data = this.responseText;
let a = document.getElementById("a");
let output = "";
// start-shorthand // start-shorthand
()=> apply_html_to_parsed_markdown(data); ()=> let apply_html_to_parsed_markdown = (md) => {
()=> md.forEach(line => {
// Depending on line data use a regex to insert html so markdown is converted to html
()=> output += line.replace(/^(regex to add html elements from markdonw line)(.*)$/g, $1$1);
});
// Output the converted file from markdown to html.
return output;
};
()=>a.innerHTML = apply_html_to_parsed_markdown(data);
// end-shorthand // end-shorthand
} }
}; };