Skip to content

Commit

Permalink
feat(rte-markdown): Added link rendering to zmi
Browse files Browse the repository at this point in the history
  • Loading branch information
cmeier76 authored and drfho committed Jan 9, 2024
1 parent c0cec60 commit 211e008
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Products/zms/plugins/rte/simplemde/manage_form.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<link rel="stylesheet" href="/++resource++zms_/simplemde/simplemde.min.css">
<script src="/++resource++zms_/simplemde/simplemde.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>

<tal:block tal:content="structure python:'<script>'"></tal:block>

Expand All @@ -38,6 +39,12 @@ var simplemde = new SimpleMDE({
"image", "table", "horizontal-rule", "clean-block", "|",
"preview", "side-by-side", "fullscreen", "guide"
],
previewRender: function(plainText, preview) { // Async method
setTimeout(function() {
preview.innerHTML = customMarkdownParser(plainText);
}, 0);
return "Loading...";
},
});

$('#attr_url_markdown').on("change", function() {
Expand Down Expand Up @@ -77,6 +84,30 @@ function zmiRichtextInit(id) {

}

function customMarkdownParser(plainText) {
text = marked.parse(plainText);

// https://stackoverflow.com/questions/136505/searching-for-uuids-in-text-with-regex
const pattern = /[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}/ig
uuids = text.match(pattern);

uuids.forEach(function(uuid) {
$.ajax({
url: '++rest_api/zmsindex',
async: false, // to set text in success below
data: {
get_uid: 'uid:' + uuid,
},
datatype: 'json',
success: function(response) {
text = text.replace('%7B$uid:' + uuid + '%7D', response[0].getPath); // incorrect path for img src
}
});
});

return text;
}

<tal:block tal:content="structure python:'</script>'"></tal:block>

<tal:block tal:define="dummy0 python:request.set('f_zmiRichtextOnSubmitEventHandler',False)"></tal:block>
Expand Down

0 comments on commit 211e008

Please sign in to comment.