Skip to content

Commit 64defc4

Browse files
committed
feat: Add conversion html to markdown
1 parent 3e7aaf5 commit 64defc4

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

public/js/collection.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
function loadCollections() {
22
chrome.storage.local.get(['kerificTerms'], function (result) {
33
let domString = '';
4+
let domStringMarkdown = '';
45

56
if (result.kerificTerms === undefined) {
67
domString = '<p>No terms found</p>';
8+
domStringMarkdown = '<p>No terms found</p>';
79
} else {
810
const terms = result.kerificTerms.terms;
911
for (let i = 0; i < terms.length; i++) {
@@ -26,12 +28,34 @@ function loadCollections() {
2628
This definition comes from: ${terms[i].organisation}
2729
</p>
2830
</div>
31+
</div>
32+
`;
2933

34+
domStringMarkdown += `
35+
<div class="card mb-5">
36+
<div class="card-header">
37+
<h2>${terms[i].term}</h2>
38+
</div>
39+
<div class="card-body">
40+
<p class="card-text">
41+
${terms[i].definition}
42+
</p>
43+
</div>
44+
<div class="card-footer">
45+
<p class="card-text">
46+
This definition comes from: ${terms[i].organisation}
47+
</p>
48+
</div>
3049
</div>
3150
`;
3251
}
52+
53+
domString += `
54+
<h2>In Markdown-format:</h2>
55+
<div id="markdown-container"></div>`;
3356
}
3457
document.getElementById('container-collection').innerHTML = domString;
58+
document.getElementById('container-collection-for-markdown').innerHTML = domStringMarkdown;
3559

3660
var removeButtons = document.querySelectorAll('.remove-button');
3761
console.log('removeButtons: ', removeButtons);
@@ -44,6 +68,22 @@ function loadCollections() {
4468
});
4569
});
4670
}
71+
72+
const turndownService = new TurndownService()
73+
const markdown = turndownService.turndown(document.getElementById('container-collection-for-markdown'))
74+
// console.log('markdown: ', markdown);
75+
76+
const markdownContainer = document.getElementById('markdown-container');
77+
markdownContainer.innerHTML = `
78+
<textarea rows="50" cols="33" class="form-control" id="markdown" rows="3">${markdown}</textarea>
79+
`;
80+
81+
markdownContainer.addEventListener('click', function (e) {
82+
console.log(e.target);
83+
e.target.select();
84+
});
85+
// markdownContainer.select();
86+
4787
});
4888

4989
chrome.storage.local.get(['role'], function (result) {

0 commit comments

Comments
 (0)