Self-Parsing-Markdown-Seite mit benutzerdefiniertem JavaScript

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Self-Parsing-Markdown-Seite mit benutzerdefiniertem JavaScript

by Anonymous » 20 Mar 2025, 21:58

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)

Top