Skip to content
Snippets Groups Projects
Commit f90fe55e authored by Emmanuel Raviart's avatar Emmanuel Raviart
Browse files

Quick & dirty prefiguration of metsLesLiens when displaying article.

parent e08c6218
Branches
Tags 0.0.202
No related merge requests found
Pipeline #5810 passed
......@@ -8,6 +8,7 @@
Article,
LegalObject,
LegalObjectType,
Lien,
} from "@tricoteuses/legal-explorer"
import LienView from "$lib/components/legifrance/LienView.svelte"
......@@ -24,6 +25,7 @@
$: legifranceUrl = legifranceUrlFromLegalObject("article", article)
$: liens = [...iterArrayOrSingleton(article.LIENS?.LIEN)]
$: contenu = metLesLiens(article.BLOC_TEXTUEL.CONTENU, liens)
$: ciblesCreation = liens.filter(
(lien) => lien["@sens"] === "cible" && lien["@typelien"] === "CREATION",
)
......@@ -31,7 +33,7 @@
$: texte = article.CONTEXTE.TEXTE
$: titreTexte = firstValueOfArrayOrSingleton(texte.TITRE_TXT)?.["#text"]
export function legifranceUrlFromLegalObject(
function legifranceUrlFromLegalObject(
type: LegalObjectType,
object: LegalObject,
): string | undefined {
......@@ -47,6 +49,23 @@
return undefined
}
}
function metLesLiens(contenu: string, liens: Lien[]): string {
for (const lien of liens) {
if (lien["@sens"] === "source" && lien["@typelien"] === "CITATION") {
const num = lien["@num"]
const match = num.match(/^(A|D|LO|L|R)(.+)$/)
if (match !== null) {
console.log(match[1], match[2])
}
contenu = contenu.replaceAll(
`article ${match[1]}. ${match[2]}`,
`<a href="https://www.legifrance.gouv.fr/codes/article_lc/${lien["@id"]}" target="_blank">$&</a>`,
)
}
}
return contenu
}
</script>
<div class="grid grid-cols-1 gap-x-8 sm:grid-cols-3">
......@@ -104,7 +123,7 @@
{/if}
<div class="prose font-serif">
{@html article.BLOC_TEXTUEL.CONTENU}
{@html contenu}
</div>
{#if ciblesCreation.length > 0}
......
......@@ -15,7 +15,6 @@
export let level = 1
export let lien: Lien
export let article: Article
let open = false
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment