-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible fix of #2 #18
base: master
Are you sure you want to change the base?
Changes from 2 commits
093710e
3288a7a
ea501b4
44a7f42
01d5523
36b9f62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
import os | ||
import subprocess | ||
import datetime | ||
import re | ||
from path import path | ||
from bs4 import BeautifulSoup | ||
from marcheolex import logger | ||
|
@@ -133,6 +134,9 @@ def creer_historique_texte(texte, format, dossier, cache): | |
# Créer les sections (donc tout le texte) | ||
contenu = creer_sections(contenu, 1, None, versions_sections, articles, version_texte, cid, cache) | ||
|
||
# Ajouter des liens internes vers articles | ||
contenu = ajouter_liens_internes(contenu) | ||
|
||
# Enregistrement du fichier | ||
f_texte = open(fichier, 'w') | ||
f_texte.write(contenu.encode('utf-8')) | ||
|
@@ -210,3 +214,30 @@ def creer_articles_section(texte, niveau, version_section_parente, articles, ver | |
|
||
return texte | ||
|
||
|
||
def ajouter_liens_internes(contenu): | ||
|
||
# Corrections mineures pour les décrets * | ||
for l in ['R', 'D']: | ||
contenu = contenu.replace(l + '* ', l + '*') # suppr. un espace en + dans l'art. | ||
contenu = contenu.replace(l + '. * ', l + '*. ') # corrig. mauvais formattages | ||
contenu = contenu.replace(l + '. *', l + '*. ') | ||
contenu = contenu.replace(l + '.* ', l + '*. ') | ||
contenu = contenu.replace(l + '.*', l + '*. ') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je suis pas trop fan de modifier le texte, même s’il a des coquilles comme ça, mais je comprend que ça soit plus facile à manipuler pour rajouter les liens. J’hésite entre deux propositions :
|
||
|
||
# Ajouter un lien interne vers l'article en question | ||
lignes = [l.strip() for l in contenu.split('\n')] | ||
for ligne in lignes: | ||
info = ligne.partition('# Article ')[2] | ||
if info: | ||
ind = re.search('\d', info).start() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ce passage bugue lorsqu’il n’y a pas de chiffre, par exemple « Article Annexe II » (code la propriété intellectuelle, version consolidée au 20 novembre 1998). |
||
type_article = info[:ind] | ||
num_article = info[ind:] | ||
article = type_article + '. ' + num_article | ||
contenu = contenu.replace(type_article + '.' + num_article, article) | ||
type_article_lien = type_article.lower().replace('*', '') | ||
article_avec_lien = '[' + article.replace('*', r'\*') + ']' + \ | ||
'(#article-' + type_article_lien + num_article + ')' | ||
for symbole in [' ', ',', '.']: # rechercher des mots exacts | ||
contenu = contenu.replace(article + symbole, article_avec_lien + symbole) | ||
return contenu | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rajouter une fin de ligne normale dans un prochain commit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ajouter donc un switch (~feature toggle) à cet endroit-là pour créer une option de format, cf #20.