Self-Parsing-Markdown-Seite mit benutzerdefiniertem JavaScriptJavaScript

Javascript-Forum
Anonymous
 Self-Parsing-Markdown-Seite mit benutzerdefiniertem JavaScript

Post by Anonymous »

Ich habe eine selbst parerne HTML

Code: Select all




**strong** and mark

gray


< /code>
markdown-it.js
:

Code: Select all

'use strict';

window.onload = function() {
const markdown = document.querySelector('noscript').innerHTML;
const md = window.markdownit({
html: true, linkify: false, typographer: true
});
const html = md.render(markdown);
document.querySelector('body').innerHTML = html;
}
< /code>
It works.
Now, I want that page to show my browser and IP time zones.




**strong** and mark

gray



&ZeroWidthSpace;

< /code>
time-zones.js
:

Code: Select all

'use strict';

(async () => {
const displayEl = document.querySelector("#time-zones");
try {
displayEl.textContent =
Intl.DateTimeFormat().resolvedOptions().timeZone + " — " +
(await (await fetch(`https://ipapi.co/json`)).json()).timezone;
} catch ({message}) {
displayEl.textContent = 'Error: ' + message;
}
})();
< /code>
But this doesn't work. I mean, the time-zones.js
Code ist korrekt, aber es gibt ein Problem, das verhindert, dass er auf einer Markdown -Seite funktioniert. Wie kann dies behoben werden?

Code: Select all

window.onload = function() {
const markdown = document.querySelector('noscript').innerHTML;
const md = window.document.querySelector('noscript').markdownit({
html: true, linkify: false, typographer: true
});
const html = md.render(markdown);
document.querySelector('noscript').innerHTML = html;
}
< /code>
TypeError: window.document.querySelector('noscript').markdownit is not a function. (In 'window.document.querySelector('noscript').markdownit({
html: true, linkify: false, typographer: true
})', 'window.document.querySelector('noscript').markdownit' is undefined)

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post