From efbfe7a6759d604a022fb5e6593ce456b9215180 Mon Sep 17 00:00:00 2001 From: daxid <david.rouquet@tetras-libre.fr> Date: Tue, 14 Jan 2025 10:07:03 +0100 Subject: [PATCH] comments and anchors --- tetras_extraction/script/src/transform.py | 21 +++++++++++++++++++ .../script/templates/activite.rq | 5 ++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/tetras_extraction/script/src/transform.py b/tetras_extraction/script/src/transform.py index 10ae8ff..bb0d8df 100644 --- a/tetras_extraction/script/src/transform.py +++ b/tetras_extraction/script/src/transform.py @@ -41,6 +41,16 @@ def prepareHTMLforMD(str): # Identify image content and add markups to identify them in the MD regexIMG = re.compile(r"<img.*?src=\"\.\./media/(.*?)\".*?>") str = regexIMG.sub(r"@IMAGESTART\1@IMAGEEND", str) + # Identify words supporting comments and add markups to identify them in the MD + regexANCHOR= re.compile(r"<a class=\"STY_lienComt\" href=\"javascript:CRS_afficherDetail\('(.)'\)\" onclick=\"enrPosClic\(event,'.'\)\">(.*?)</a>") + str = regexANCHOR.sub(r"@ANCHORSTART@\1@\2@ANCHOREND", str) + # Identify anchor words with related comment id and add markups to identify them in the MD + regexANCHOR= re.compile(r"<a class=\"STY_lienComt\" href=\"javascript:CRS_afficherDetail\('(.)'\)\" onclick=\"enrPosClic\(event,'.'\)\">(.*?)</a>") + str = regexANCHOR.sub(r"@ANCHORSTART@\1@\2@ANCHOREND", str) + # Identify comments ids and add markups to identify them in the MD + regexCOMMENTID= re.compile(r"<div id=\"divCmt(.)\" onclick=\"SPE_clicDansBulle\(event,'.'\)\">")#(.*)</div>", re.MULTILINE) + str = regexCOMMENTID.sub(r"@COMMENTIDSTART@\1@COMMENTIDEND", str) + return(str) @@ -70,6 +80,17 @@ def postEditMD(str): str = str.replace(imageElt, imgHtml) ################################################### + ################################################### + # Add html code to MD for comment anchors + ################################################### + # First for the words supporting the comments + regexANCHOR = re.compile(r"@ANCHORSTART@(.)@(.*?)@ANCHOREND") + str = regexANCHOR.sub(r"<span commentaireInfoId='\1'>\2</span>", str) + + # For the comments themselves it is done in activite.rq + + ################################################### + # Add html for images and fix media paths regexIMG = re.compile(r"!\[\]\(\.\./media/(.*?)\)") str = regexIMG.sub(r"<img src='/macao-hugo/media/\1'>", str) diff --git a/tetras_extraction/script/templates/activite.rq b/tetras_extraction/script/templates/activite.rq index ad2284f..c138254 100644 --- a/tetras_extraction/script/templates/activite.rq +++ b/tetras_extraction/script/templates/activite.rq @@ -15,10 +15,9 @@ template mt:activite(?act) { ?desc st:nl() - '<div class="commentaireInfoGroup">' st:nl() + '<div class="commentaireInfoGroup" hidden="True">' st:nl() group { - '<div class="commentaireInfo">' st:nl() - ?info_comment + concat(replace(replace(?info_comment,'@COMMENTIDSTART@','<div class="commentaireInfo" id="'),'@COMMENTIDEND','">'),'</div>') '</div>' st:nl() } '</div>' st:nl() -- GitLab