Skip to content
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

New implementation of notes #28

Merged
merged 2 commits into from Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions modele-article.org
Expand Up @@ -61,30 +61,34 @@ ci-dessus. Essayez de commenter votre code et vos commandes shell de
manière à ne pas avoir d'immenses blocs de code ou de sorties shell
qui rendent l'article illisible.

#+ATTR_LINUXMAG-FR: :note PAO
#+begin_note_pao
Le texte ici est destiné à indiquer des informations supplémentaires à
la rédaction. Il n'apparaîtra pas dans l'article final.
#+end_note_pao

Pour une note apparaissant dans l'article final il faut seulement
supprimer le terme PAO :

#+ATTR_LINUXMAG-FR: :note t
#+begin_note
Le texte présent ici, rédigé en style « Normal », apparaîtra dans
l'article final dans une boîte spéciale « note ».
#+end_note

Les indications en style « pragma », comme ci-dessus, doivent toujours
être encadrées de 3 slashs ​/​/​/​…/​/​/.

Si vous souhaitez une note ayant pour titre : Avertissement ou
Attention (avec la petite icône associée), il faut utiliser :

#+ATTR_LINUXMAG-FR: :note attention
#+begin_note_attention
Le texte présent ici, rédigé en style « Normal », apparaîtra dans
l'article final dans une boîte spéciale « Attention ».
#+end_note_attention

#+ATTR_LINUXMAG-FR: :note avertissement
#+begin_note_avertissement
Le texte présent ici, rédigé en style « Normal », apparaîtra dans
l'article final dans une boîte spéciale « Avertissement ».
#+end_note_avertissement

Les sessions de commandes interactives sont à utiliser avec le style
de paragraphe « console ». On peut également mettre en évidence
Expand Down
49 changes: 28 additions & 21 deletions ox-linuxmag-fr.el
Expand Up @@ -331,40 +331,43 @@ INFO is a plist holding contextual information."
"Transcode a PARAGRAPH element from Org to ODT.
CONTENTS is the contents of the paragraph, as a string. INFO is
the plist used as a communication channel."
(let ((note-type (org-export-read-attribute :attr_linuxmag-fr paragraph :note)))
(cond
(note-type
(ox-linuxmag-fr--format-note contents note-type))
((ox-linuxmag-fr--is-paragraph-a-figure-p paragraph info)
(ox-linuxmag-fr--format-figure paragraph contents info))
(t
(let* ((parent (org-export-get-parent paragraph))
(parent-type (org-element-type parent))
(prefix (when (eq parent-type 'item) "- ")))
(org-odt--format-paragraph
paragraph
(concat prefix contents)
info
"Normal" "" ""))))))
(cond
((ox-linuxmag-fr--is-paragraph-a-figure-p paragraph info)
(ox-linuxmag-fr--format-figure paragraph contents info))
(t
(let* ((parent (org-export-get-parent paragraph))
(parent-type (org-element-type parent))
(prefix (when (eq parent-type 'item) "- "))
(style (if (and
(eq parent-type 'special-block)
(equal (org-element-property :type parent) "note_pao"))
"pragma"
"Normal")))
(org-odt--format-paragraph
paragraph
(concat prefix contents)
info
style
"" "")))))

(defun ox-linuxmag-fr--format-note (contents note-type)
"Return a string containing CONTENTS with a box markup.

NOTE-TYPE is a string representing the kind of box."
(cl-case (intern note-type)
NOTE-TYPE is a symbol representing the kind of box."
(cl-case note-type
(PAO (concat
(ox-linuxmag-fr--format-pragma "Début note PAO")
(ox-linuxmag-fr--format-textp contents "pragma")
contents
(ox-linuxmag-fr--format-pragma "Fin note PAO")))
((attention avertissement)
(concat
(ox-linuxmag-fr--format-pragma (format "Début note : %s" (capitalize note-type)))
(ox-linuxmag-fr--format-textp contents)
(ox-linuxmag-fr--format-pragma (format "Début note : %s" (capitalize (symbol-name note-type))))
contents
(ox-linuxmag-fr--format-pragma "Fin note")))
(t
(concat
(ox-linuxmag-fr--format-pragma (format "Début note"))
(ox-linuxmag-fr--format-textp contents)
contents
(ox-linuxmag-fr--format-pragma "Fin note")))))

(defun ox-linuxmag-fr--format-figure (paragraph _contents info)
Expand Down Expand Up @@ -397,6 +400,10 @@ contextual information."
(let ((type (intern (org-element-property :type special-block))))
(cl-case type
(encadre (ox-linuxmag-fr--format-encadre special-block contents))
(note (ox-linuxmag-fr--format-note contents 'default))
(note_pao (ox-linuxmag-fr--format-note contents 'PAO))
(note_avertissement (ox-linuxmag-fr--format-note contents 'avertissement))
(note_attention (ox-linuxmag-fr--format-note contents 'attention))
(t contents))))

(defun ox-linuxmag-fr--format-encadre (special-block contents)
Expand Down
40 changes: 32 additions & 8 deletions test/ox-linuxmag-fr-tests.el
Expand Up @@ -170,27 +170,51 @@ See figure [[mypicture2]].")
(should (ox-linuxmag-fr-tests-contain "Foo <text:span text:style-name=\"url\">https://damien.cassou.me</text:span>")))

(ert-deftest ox-linuxmag-fr-tests-paragraph-note-PAO ()
(ox-linuxmag-fr-tests-export "#+ATTR_LINUXMAG-FR: :note PAO\nLe texte")
(ox-linuxmag-fr-tests-export "
#+begin_note_pao
Le texte
#+end_note_pao")
(should (ox-linuxmag-fr-tests-contain "<text:p text:style-name=\"pragma\">/// Début note PAO ///</text:p>"))
(should (ox-linuxmag-fr-tests-contain "<text:p text:style-name=\"pragma\">Le texte</text:p>"))
(should (ox-linuxmag-fr-tests-contain "<text:p text:style-name=\"pragma\">Le texte\n</text:p>"))
(should (ox-linuxmag-fr-tests-contain "<text:p text:style-name=\"pragma\">/// Fin note PAO ///</text:p>")))

(ert-deftest ox-linuxmag-fr-tests-paragraph-note-attention ()
(ox-linuxmag-fr-tests-export "#+ATTR_LINUXMAG-FR: :note attention\nLe texte")
(ox-linuxmag-fr-tests-export "
#+begin_note_attention
Le texte
#+end_note_attention")
(should (ox-linuxmag-fr-tests-contain "<text:p text:style-name=\"pragma\">/// Début note : Attention ///</text:p>"))
(should (ox-linuxmag-fr-tests-contain "<text:p text:style-name=\"Normal\">Le texte</text:p>"))
(should (ox-linuxmag-fr-tests-contain "<text:p text:style-name=\"Normal\">Le texte\n</text:p>"))
(should (ox-linuxmag-fr-tests-contain "<text:p text:style-name=\"pragma\">/// Fin note ///</text:p>")))

(ert-deftest ox-linuxmag-fr-tests-paragraph-note-avertissement ()
(ox-linuxmag-fr-tests-export "#+ATTR_LINUXMAG-FR: :note avertissement\nLe texte")
(ox-linuxmag-fr-tests-export "
#+begin_note_avertissement
Le texte
#+end_note_avertissement")
(should (ox-linuxmag-fr-tests-contain "<text:p text:style-name=\"pragma\">/// Début note : Avertissement ///</text:p>"))
(should (ox-linuxmag-fr-tests-contain "<text:p text:style-name=\"Normal\">Le texte</text:p>"))
(should (ox-linuxmag-fr-tests-contain "<text:p text:style-name=\"Normal\">Le texte\n</text:p>"))
(should (ox-linuxmag-fr-tests-contain "<text:p text:style-name=\"pragma\">/// Fin note ///</text:p>")))

(ert-deftest ox-linuxmag-fr-tests-paragraph-note-default ()
(ox-linuxmag-fr-tests-export "#+ATTR_LINUXMAG-FR: :note t\nLe texte")
(ox-linuxmag-fr-tests-export "
#+begin_note
Le texte
#+end_note")
(should (ox-linuxmag-fr-tests-contain "<text:p text:style-name=\"pragma\">/// Début note ///</text:p>"))
(should (ox-linuxmag-fr-tests-contain "<text:p text:style-name=\"Normal\">Le texte\n</text:p>"))
(should (ox-linuxmag-fr-tests-contain "<text:p text:style-name=\"pragma\">/// Fin note ///</text:p>")))

(ert-deftest ox-linuxmag-fr-tests-paragraph-note-default-several-paragraphs ()
(ox-linuxmag-fr-tests-export "
#+begin_note
Le texte

Autre texte
#+end_note")
(should (ox-linuxmag-fr-tests-contain "<text:p text:style-name=\"pragma\">/// Début note ///</text:p>"))
(should (ox-linuxmag-fr-tests-contain "<text:p text:style-name=\"Normal\">Le texte</text:p>"))
(should (ox-linuxmag-fr-tests-contain "<text:p text:style-name=\"Normal\">Le texte\n</text:p>"))
(should (ox-linuxmag-fr-tests-contain "<text:p text:style-name=\"Normal\">Autre texte\n</text:p>"))
(should (ox-linuxmag-fr-tests-contain "<text:p text:style-name=\"pragma\">/// Fin note ///</text:p>")))

(ert-deftest ox-linuxmag-fr-tests-paragraph-picture ()
Expand Down