I am building markdown previewer and I want to add a placeholder for my element.
Placeholder is written in markdown and I am trying to import it to my index.js file
import placeholder from './sample.md'; // Importing from the local folder
const $ = document.querySelectorAll.bind(document);
marked.setOptions({
breaks: true
});
let renderer = new marked.Renderer();
renderer.link = function(href, title, text) {
return `<a target="_blank" href="${href}">${text}` + `</a>`
}
let txtArea = $('textarea')[0];
txtArea.addEventListener('input', event => {
$('.prev-text')[0].innerHTML = marked(event.target.value, {renderer: renderer})
});
I want to use the content of the “sample.md” and save it to a variable “placeholder” so that I can set it as a default text inside my .
Right now I cannot load the “sample.md”, browser is throwing this error:“Failed to load module script: The server responded with a non-JavaScript MIME type of “text/markdown”. Strict MIME type checking is enforced for module scripts per HTML spec.”
Here is my HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./style.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.3/css/all.css" integrity="sha384-SZXxX4whJ79/gErwcOYf+zWLeJdY/qpuqC4cAa9rOGUstPomtqpuNWT9wdPEn2fk" crossorigin="anonymous">
<title>Markdown Previewer</title>
</head>
<body>
<div class="container">
<div class="editor">
<div id="ed-navbar" class="navbar">
EDITOR
</div>
<textarea name="markdown"></textarea>
</div>
<div class="preview">
<div id="pr-navbar" class="navbar">
PREVIEW
</div>
<div class="prev-text">
</div>
</div>
</div>
<script type="module" src="./index.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
</body>
</html>