From 501fd9b90b1565e9e9a346c26706ae414f0417d7 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Fri, 13 Mar 2015 21:51:07 +0100 Subject: [PATCH 2/2] ox: Add inclusion of KEYWORDS * ox-html.el (org-html-style-default): Add .keywords-value and .keywords-prefix style. (org-html-with-keywords,org-html-keywords-prefix): New variable. (org-html-keyword): Allow preliminary keywords inclusion. * ox-ascii.el (org-ascii-with-keywords) (org-ascii-keyword-prefix): New variable. (org-ascii-keyword): Allow keywords includsion. * ox-latex.el (org-latex-with-keywords) (org-latex-keywords-prefix, org-latex-keywords-template): New variable. (org-latex-keyword): Allow keywords inclusion. * ox-odt.el (org-odt-with-keywords), (org-odt-keywords-prefix): New variable. (org-odt-keyword): Allow keywords inclusion. * OrgOdtStyles.xml (OrgKeywordsPrefix, OrgKeywords): New style. * ox.el (org-export-dictionary): Add "Keywords". This allow constructs like this: #+begin_abstract my abstract #+keywords: markup, keywords, org-mode #+end_abstract --- etc/styles/OrgOdtStyles.xml | 4 ++++ lisp/ox-ascii.el | 34 ++++++++++++++++++++++++++++++-- lisp/ox-html.el | 45 +++++++++++++++++++++++++++++++++++++++++-- lisp/ox-latex.el | 47 ++++++++++++++++++++++++++++++++++++++++----- lisp/ox-odt.el | 34 +++++++++++++++++++++++++++++++- lisp/ox.el | 5 +++++ 6 files changed, 159 insertions(+), 10 deletions(-) diff --git a/etc/styles/OrgOdtStyles.xml b/etc/styles/OrgOdtStyles.xml index 1a8edee..c9710b9 100644 --- a/etc/styles/OrgOdtStyles.xml +++ b/etc/styles/OrgOdtStyles.xml @@ -416,6 +416,10 @@ + + + + diff --git a/lisp/ox-ascii.el b/lisp/ox-ascii.el index d5517bc..13e6ff7 100644 --- a/lisp/ox-ascii.el +++ b/lisp/ox-ascii.el @@ -121,7 +121,8 @@ org-ascii-filter-comment-spacing) (:filter-section . org-ascii-filter-headline-blank-lines)) :options-alist - '((:ascii-bullets nil nil org-ascii-bullets) + '((:keywords "KEYWORDS" nil nil space) + (:ascii-bullets nil nil org-ascii-bullets) (:ascii-caption-above nil nil org-ascii-caption-above) (:ascii-charset nil nil org-ascii-charset) (:ascii-global-margin nil nil org-ascii-global-margin) @@ -142,7 +143,9 @@ (:ascii-table-widen-columns nil nil org-ascii-table-widen-columns) (:ascii-text-width nil nil org-ascii-text-width) (:ascii-underline nil nil org-ascii-underline) - (:ascii-verbatim-format nil nil org-ascii-verbatim-format))) + (:ascii-verbatim-format nil nil org-ascii-verbatim-format) + (:keywords-prefix nil nil org-ascii-keywords-prefix) + (:with-keywords nil "keywords" org-ascii-with-keywords))) @@ -410,6 +413,22 @@ nil to ignore the inline task." :package-version '(Org . "8.3") :type 'function) +(defcustom org-ascii-keywords-prefix t + "Nonnil means prefix keywords. +If the value is a string the string is used. Otherwise the +translation of \"Keywords\" from `org-export-dictionary' is used." + :group 'org-export-ascii + :version "25.1" + :package-version '(Org . "8.3") + :type '(choice boolean string)) + +(defcustom org-ascii-with-keywords nil + "Nonnil means print keywords." + :group 'org-export-ascii + :version "25.1" + :package-version '(Org . "8.3") + :type 'boolean) + ;;; Internal Functions @@ -1470,6 +1489,17 @@ information." (value (org-element-property :value keyword))) (cond ((string= key "ASCII") (org-ascii--justify-element value keyword info)) + ((and (string= key "KEYWORDS") + (plist-get info :with-keywords)) + (format "%s%s" + (let ((prefix (plist-get :keywords-prefix info))) + (cond ((stringp prefix) prefix) + (prefix + (concat (org-export-translate "Keywords" + (plist-get info :ascii-charset) info) + ": ")) + (t ""))) + (org-export-data value info))) ((string= key "TOC") (org-ascii--justify-element (let ((case-fold-search t)) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 21e6122..11aed01 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -173,7 +173,9 @@ (:creator "CREATOR" nil org-html-creator-string) (:with-latex nil "tex" org-html-with-latex) ;; Retrieve LaTeX header for fragments. - (:latex-header "LATEX_HEADER" nil nil newline))) + (:latex-header "LATEX_HEADER" nil nil newline) + (:keywords-prefix nil nil org-html-keywords-prefix) + (:with-keywords nil "keywords" nil org-html-with-keywords))) ;;; Internal Variables @@ -285,7 +287,7 @@ for the JavaScript code in this tag. .left { margin-left: 0px; margin-right: auto; text-align: left; } .center { margin-left: auto; margin-right: auto; text-align: center; } .underline { text-decoration: underline; } - #postamble p, #preamble p { font-size: 90%; margin: .2em; } + #keywords p, #postamble p, #preamble p { font-size: 90%; margin: .2em; } p.verse { margin-left: 3%; } pre { border: 1px solid #ccc; @@ -340,6 +342,8 @@ for the JavaScript code in this tag. margin: 10px; background: #ffffcc; } + .keywords-value { font-style:normal; } + .keywords-prefix { font-style:italic; } #org-div-home-and-up { text-align: right; font-size: 70%; white-space: nowrap; } textarea { overflow-x: auto; } @@ -720,6 +724,24 @@ The function should return the string to be exported." :package-version '(Org . "8.3") :type 'function) +;;;; Keywords + +(defcustom org-html-keywords-prefix t + "Nonnil means prefix keywords. +If the value is a string the string is used. Otherwise the +translation of \"Keywords\" from `org-export-dictionary' is used." + :group 'org-export-html + :type '(choice boolean string) + :version "25.1" + :package-version '(Org . "8.3")) + +(defcustom org-html-with-keywords t + "Nonnil means include keywords." + :group 'org-export-html + :version "25.1" + :package-version '(Org . "8.3") + :type 'boolean) + ;;;; LaTeX (defcustom org-html-with-latex org-export-with-latex @@ -2571,6 +2593,25 @@ CONTENTS is nil. INFO is a plist holding contextual information." (value (org-element-property :value keyword))) (cond ((string= key "HTML") value) + ((and (string= key "KEYWORDS") + (plist-get info :with-keywords)) + (format "

%s%s\n

" + (let ((prefix (plist-get :keywords-prefix info))) + (if prefix + (format + "%s " + (if (stringp prefix) prefix + (concat (org-export-translate "Keywords" :html info) ":"))) + "")) + ;; TODO: there should be a possibility to automatically + ;; add hrefs so each keyword. Like a blog... Perhaps + ;; this should just call a function on each keyword. + ;; Further, I guess the correct "semantic" way would be + ;; to print it as a oneline list. However, then we + ;; would need to make assumptions on how to split + ;; values. Both comma and space makes sense for this. + (format "%s" + (org-export-data value info)))) ((string= key "TOC") (let ((case-fold-search t)) (cond diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index f3c47dc..1d9475c 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -132,6 +132,7 @@ (:latex-inactive-timestamp-format nil nil org-latex-inactive-timestamp-format) (:latex-inline-image-rules nil nil org-latex-inline-image-rules) (:latex-link-with-unknown-path-format nil nil org-latex-link-with-unknown-path-format) + (:latex-keywords-template nil nil org-latex-keywords-template) (:latex-listings nil nil org-latex-listings) (:latex-listings-langs nil nil org-latex-listings-langs) (:latex-listings-options nil nil org-latex-listings-options) @@ -143,6 +144,8 @@ (:latex-text-markup-alist nil nil org-latex-text-markup-alist) (:latex-title-command nil nil org-latex-title-command) (:latex-toc-command nil nil org-latex-toc-command) + (:keywords-prefix nil nil org-latex-keywords-prefix) + (:with-keywords nil "keywords" org-latex-with-keywords) ;; Redefine regular options. (:date "DATE" nil "\\today" t))) @@ -538,15 +541,40 @@ and resolve links into section references." :type 'string) -;;;; Links +;;;; Keywords -(defcustom org-latex-image-default-option "" - "Default option for images." +(defcustom org-latex-with-keywords nil + "Nonnil means that keywords are included in the output. +When nil, keywords are not exported. This option can also be set +with the OPTIONS keyword, e.g. \"keywords:nil\"." :group 'org-export-latex - :version "24.4" - :package-version '(Org . "8.0") + :type 'boolean + :version "25.1" + :package-version '(Org . "8.3")) + +(defcustom org-latex-keywords-prefix t + "Nonnil means prefix keywords. +If the value is a string the string is used. Otherwise the +translation of \"Keywords\" from `org-export-dictionary' is used. +See also `org-latex-keywords-template'." + :group 'org-export-latex + :type '(choice boolean string) + :version "25.1" + :package-version '(Org . "8.3")) + +(defcustom org-latex-keywords-template "\\par\\smallskip\n\\noindent{{\\itshape %s} %s}\n" + "Template used for printed keywords. +Should contain two \"%s\"-expressions. The first is set +according to org-latex-keywords-prefix and the second with the +value of the keywords." + :group 'org-export-latex + :version "25.1" + :package-version '(Org . "8.3") :type 'string) + +;;;; Links + (defcustom org-latex-image-default-width ".9\\linewidth" "Default width for images. This value will not be used if a height is provided." @@ -1821,6 +1849,15 @@ CONTENTS is nil. INFO is a plist holding contextual information." (cond ((string= key "LATEX") value) ((string= key "INDEX") (format "\\index{%s}" value)) + ((and (string= key "KEYWORDS") + (plist-get info :with-keywords)) + (format (plist-get info :latex-keywords-template) + (let ((prefix (plist-get info :keywords-prefix))) + (cond ((stringp prefix) prefix) + (prefix + (concat (org-export-translate "Keywords" nil info) ":")) + (t ""))) + (org-export-data value info))) ((string= key "TOC") (let ((case-fold-search t)) (cond diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el index dd3020e..fee83ec 100644 --- a/lisp/ox-odt.el +++ b/lisp/ox-odt.el @@ -113,7 +113,9 @@ (:odt-table-styles nil nil org-odt-table-styles) (:odt-use-date-fields nil nil org-odt-use-date-fields) ;; Redefine regular option. - (:with-latex nil "tex" org-odt-with-latex))) + (:with-latex nil "tex" org-odt-with-latex) + (:keywords-prefix nil nil org-odt-keywords-prefix) + (:with-keywords nil "keywords" org-odt-with-keywords))) ;;; Dependencies @@ -747,6 +749,23 @@ t Synonym for `mathjax'." (const :tag "Use MathJax to display math" mathjax) (const :tag "Leave math verbatim" verbatim))) +;;;; Keywords + +(defcustom org-odt-keywords-prefix t + "Nonnil means prefix keywords. +If the value is a string the string is used. Otherwise the +translation of \"Keywords\" from `org-export-dictionary' is used." + :group 'org-odt-latex + :type '(choice boolean string) + :version "25.1" + :package-version '(Org . "8.3")) + +(defcustom org-odt-with-keywords nil + "Nonnil means include keywords." + :group 'org-export-odt + :version "25.1" + :package-version '(Org . "8.3") + :type 'boolean) ;;;; Links @@ -2030,6 +2049,19 @@ information." ((string= key "INDEX") ;; FIXME (ignore)) + ((and (string= key "KEYWORDS") + (plist-get info :with-keywords)) + (format "%s%s\n\n" + (let ((prefix (plist-get info ::keywords-prefix))) + (if prefix + (format "%s: " + "OrgKeywordsPrefix" + (if (stringp prefix) prefix + (org-export-translate "Keywords" nil info))) + "")) + (format "%s" + "OrgKeywords" + (org-export-data value info)))) ((string= key "TOC") (let ((case-fold-search t)) (cond diff --git a/lisp/ox.el b/lisp/ox.el index 213e56d..af12216 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -5433,6 +5433,11 @@ them." :utf-8 "Примітки") ("zh-CN" :html "脚注" :utf-8 "脚注") ("zh-TW" :html "腳註" :utf-8 "腳註")) + ("Keywords" + ("da" :default "Nøgleord") + ("de" :default "Schlüsselworter") + ("se" :default "Nyckelord") + ("no" :default "Nøkkelord")) ("List of Listings" ("da" :default "Programmer") ("de" :default "Programmauflistungsverzeichnis") -- 2.3.2