Skip to content

Commit

Permalink
Ajout l'exportation HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
emmadiblo authored Dec 28, 2024
1 parent fd4b64b commit 50d1a4a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ <h3>EditoMark</h3>
<button id="upload" class="button">📂 Ouvrir</button>
<button id="download" class="button">⬇️ Télécharger</button>
<button id="copy" class="button">📋 Copier</button>
<button id="download-html" class="button">📄 Exporter en HTML</button>
</div>
</div>

Expand Down
46 changes: 44 additions & 2 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const copyButton = document.getElementById('copy');
const themeSelect = document.getElementById('theme-select');
const wordCountElement = document.getElementById('wordCount');
const charCountElement = document.getElementById('charCount');
const downloadHtml = document.getElementById('download-html');

const editor = CodeMirror.fromTextArea(textarea, {
mode: 'markdown',
Expand Down Expand Up @@ -66,10 +67,51 @@ function downloadMarkdown() {
}

downloadButton.addEventListener('click', downloadMarkdown);
document.addEventListener('keydown', (e) => {

//desactiver les id par defaut
marked.setOptions({
headerIds: false
});

downloadHtml.addEventListener('click', () => {
const markdownText = editor.getValue();
let filename = document.getElementById('filename')?.value || 'document';
if (validateFilename(filename)) {
const htmlContent = marked(markdownText);
const blob = new Blob([htmlContent], { type: 'text/html;charset=utf-8' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `${filename}.html`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
});

document.addEventListener('keydown', async (e) => {
if (e.ctrlKey && e.key === 's') {
e.preventDefault();
downloadMarkdown();
const choice = confirm('Voulez-vous sauvegarder en HTML? (OK pour HTML, Annuler pour Markdown)');
if (choice) {
const markdownText = editor.getValue();
let filename = document.getElementById('filename')?.value || 'document';
if (validateFilename(filename)) {
const htmlContent = marked(markdownText);
const blob = new Blob([htmlContent], { type: 'text/html;charset=utf-8' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `${filename}.html`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
} else {
downloadMarkdown();
}
}
});

Expand Down

0 comments on commit 50d1a4a

Please sign in to comment.