Fix the maint branch.

Thanks to Achim Gratz for his precious help on this.
This commit is contained in:
Bastien Guerry 2012-03-19 20:27:28 +01:00
parent e0072f7913
commit c44e07a4fa
18 changed files with 549 additions and 12403 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,155 +0,0 @@
;;; org-bibtex-extras --- extras for working with org-bibtex entries
;; Copyright (C) 2008-2012 Free Software Foundation, Inc.
;; Author: Eric Schulte <eric dot schulte at gmx dot com>
;; Keywords: outlines, hypermedia, bibtex, d3
;; Homepage: http://orgmode.org
;; Version: 0.01
;; This file is not yet part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Warning: This should certainly be considered EXPERIMENTAL and still
;; in development, feedback is welcome, but don't expect it
;; to work.
;; This file add some extra functionality to your bibtex entries which
;; are stored as Org-mode headlines using org-bibtex.el. Most
;; features expect that you keep all of your reading notes in a single
;; file, set the `obe-bibtex-file' variable to the path to this file.
;;
;; - d3 view :: d3 is a Javascript library which supports interactive
;; display of graphs. To view your citations as a d3
;; graph, execute the following which will create a .json
;; export of your references file, then grab a copy of
;; d3, edit examples/force/force.js to replace
;;
;; var source`"miserables.json";
;;
;; with
;;
;; var source`"your-references.json";
;;
;; then view examples/force/force.html in your browser.
;;
;; - HTML export :: Customize the `obe-html-link-base' variable so
;; that it points to an html export of your
;; references, then add the following to your html
;; export hook, and citations will be resolved during
;; html export.
;;
;; (add-hook 'org-export-first-hook
;; (lambda ()
;; (when (equal org-export-current-backend 'html)
;; (obe-html-export-citations))))
;;; Code:
(require 'org-bibtex)
(defcustom obe-bibtex-file nil "File holding bibtex entries.")
(defcustom obe-html-link-base nil
"Base of citation links.
For example, to point to your `obe-bibtex-file' use the following.
(setq obe-html-link-base (format \"file:%s\" obe-bibtex-file))
")
(defvar obe-citations nil)
(defun obe-citations ()
"Return all citations from `obe-bibtex-file'."
(or obe-citations
(save-window-excursion
(find-file obe-bibtex-file)
(goto-char (point-min))
(while (re-search-forward " :CUSTOM_ID: \\(.+\\)$" nil t)
(push (org-babel-clean-text-properties (match-string 1))
obe-citations))
obe-citations)))
(defun obe-goto-citation (&optional citation)
"Visit a citation given its ID."
(interactive)
(let ((citation (or citation
(org-icompleting-read "Citation: "
(obe-citations)))))
(find-file obe-bibtex-file)
(goto-char (point-min))
(when (re-search-forward (format " :CUSTOM_ID: %s" citation) nil t)
(outline-previous-visible-heading 1)
t)))
(defun obe-html-export-citations ()
"Convert all \\cite{...} citations in the current file into HTML links."
(save-excursion
(goto-char (point-min))
(while (re-search-forward "\\\\cite{\\([^\000}]+\\)}" nil t)
(replace-match
(save-match-data
(mapconcat (lambda (c) (format "[[%s#%s][%s]]" obe-html-link-base c c))
(mapcar #'org-babel-trim
(split-string (match-string 1) ",")) ", "))))))
(defun obe-get-meta-data (citation)
"Collect meta-data for CITATION."
(save-excursion
(when (obe-goto-citation citation)
(let ((pt (point)))
`((:authors . ,(split-string (org-entry-get pt "AUTHOR") " and " t))
(:title . ,(org-babel-clean-text-properties (org-get-heading 1 1)))
(:journal . ,(org-entry-get pt "JOURNAL")))))))
(defun obe-meta-to-json (meta &optional fields)
"Turn a list of META data from citations into a string of json."
(let ((counter 1) nodes links)
(flet ((id (it) (position it nodes :test #'string= :key #'car))
(col (k) (mapcar (lambda (r) (cdr (assoc k r))) meta))
(add (lst)
(dolist (el lst) (push (cons el counter) nodes))
(incf counter)))
;; build the nodes of the graph
(add (col :title))
(add (remove-if (lambda (author) (string-match "others" author))
(remove-duplicates (apply #'append (col :authors))
:test #'string=)))
(dolist (field fields)
(add (remove-duplicates (col field) :test #'string=)))
;; build the links in the graph
(dolist (citation meta)
(let ((dest (id (cdr (assoc :title citation)))))
(dolist (author (mapcar #'id (cdr (assoc :authors citation))))
(when author (push (cons author dest) links)))
(let ((jid (id (cdr (assoc :journal citation)))))
(when jid (push (cons jid dest) links)))
(let ((cid (id (cdr (assoc :category citation)))))
(when cid (push (cons cid dest) links)))))
;; build the json string
(format "{\"nodes\":[%s],\"links\":[%s]}"
(mapconcat
(lambda (pair)
(format "{\"name\":%S,\"group\":%d}"
(car pair) (cdr pair)))
nodes ",")
(mapconcat
(lambda (link)
(format "{\"source\":%d,\"target\":%d,\"value\":1}"
(car link) (cdr link)))
(meta-to-links meta nodes) ",")))))
(provide 'org-bibtex-extras)
;;; org-bibtex-extras ends here

View File

@ -0,0 +1,213 @@
REM ***** BASIC *****
Dim DocTypes
Private DocTypeToFiltersMap As New Collection
Private WriterExportFilters As New Collection
Private WriterWebExportFilters As New Collection
Private CalcExportFilters As New Collection
Private ImpressExportFilters As New Collection
Private DrawExportFilters As New Collection
Private ExportFiltersInited As Boolean
Sub InitExportFilters
If ExportFiltersInited Then
Exit Sub
End If
DocTypes = Array(_
"com.sun.star.text.TextDocument", _
"com.sun.star.sheet.SpreadsheetDocument", _
"com.sun.star.presentation.PresentationDocument", _
"com.sun.star.drawing.DrawingDocument",_
"com.sun.star.text.WebDocument"_
)
With WriterExportFilters
.Add Key := "bib" , Item :=Array("bib" , "BibTeX" , "BibTeX_Writer ")
.Add Key := "doc" , Item :=Array("doc" , "Microsoft Word 97/2000/XP" , "MS Word 97 ")
.Add Key := "doc6" , Item :=Array("doc" , "Microsoft Word 6.0" , "MS WinWord 6.0 ")
.Add Key := "doc95" , Item :=Array("doc" , "Microsoft Word 95" , "MS Word 95 ")
.Add Key := "docbook" , Item :=Array("xml" , "DocBook" , "DocBook File ")
.Add Key := "html" , Item :=Array("html" , "HTML Document (OpenOffice.org Writer)" , "HTML (StarWriter) ")
.Add Key := "latex" , Item :=Array("ltx" , "LaTeX 2e" , "LaTeX_Writer ")
.Add Key := "mediawiki" , Item :=Array("txt" , "MediaWiki" , "MediaWiki ")
.Add Key := "odt" , Item :=Array("odt" , "ODF Text Document" , "writer8 ")
.Add Key := "ooxml" , Item :=Array("xml" , "Microsoft Office Open XML" , "MS Word 2003 XML ")
.Add Key := "ott" , Item :=Array("ott" , "Open Document Text" , "writer8_template ")
.Add Key := "pdf" , Item :=Array("pdf" , "Portable Document Format" , "writer_pdf_Export ")
.Add Key := "rtf" , Item :=Array("rtf" , "Rich Text Format" , "Rich Text Format ")
.Add Key := "sdw" , Item :=Array("sdw" , "StarWriter 5.0" , "StarWriter 5.0 ")
.Add Key := "sdw3" , Item :=Array("sdw" , "StarWriter 3.0" , "StarWriter 3.0 ")
.Add Key := "sdw4" , Item :=Array("sdw" , "StarWriter 4.0" , "StarWriter 4.0 ")
.Add Key := "stw" , Item :=Array("stw" , "Open Office.org 1.0 Text Document Template" , "writer_StarOffice_XML_Writer_Template ")
.Add Key := "sxw" , Item :=Array("sxw" , "Open Office.org 1.0 Text Document" , "StarOffice XML (Writer) ")
.Add Key := "text" , Item :=Array("txt" , "Text Encoded" , "Text (encoded) ")
.Add Key := "txt" , Item :=Array("txt" , "Text" , "Text ")
.Add Key := "uot" , Item :=Array("uot" , "Unified Office Format text" , "UOF text ")
.Add Key := "vor" , Item :=Array("vor" , "StarWriter 5.0 Template" , "StarWriter 5.0 Vorlage/Template ")
.Add Key := "vor3" , Item :=Array("vor" , "StarWriter 3.0 Template" , "StarWriter 3.0 Vorlage/Template ")
.Add Key := "vor4" , Item :=Array("vor" , "StarWriter 4.0 Template" , "StarWriter 4.0 Vorlage/Template ")
.Add Key := "xhtml" , Item :=Array("html" , "XHTML Document" , "XHTML Writer File ")
End With
With DrawExportFilters
.Add Key := "bmp" , Item :=Array("bmp" , "Windows Bitmap" , "draw_bmp_Export ")
.Add Key := "emf" , Item :=Array("emf" , "Enhanced Metafile" , "draw_emf_Export ")
.Add Key := "eps" , Item :=Array("eps" , "Encapsulated PostScript" , "draw_eps_Export ")
.Add Key := "gif" , Item :=Array("gif" , "Graphics Interchange Format" , "draw_gif_Export ")
.Add Key := "html" , Item :=Array("html" , "HTML Document (OpenOffice.org Draw)" , "draw_html_Export ")
.Add Key := "jpg" , Item :=Array("jpg" , "Joint Photographic Experts Group" , "draw_jpg_Export ")
.Add Key := "met" , Item :=Array("met" , "OS/2 Metafile" , "draw_met_Export ")
.Add Key := "odd" , Item :=Array("odd" , "OpenDocument Drawing" , "draw8 ")
.Add Key := "otg" , Item :=Array("otg" , "OpenDocument Drawing Template" , "draw8_template ")
.Add Key := "pbm" , Item :=Array("pbm" , "Portable Bitmap" , "draw_pbm_Export ")
.Add Key := "pct" , Item :=Array("pct" , "Mac Pict" , "draw_pct_Export ")
.Add Key := "pdf" , Item :=Array("pdf" , "Portable Document Format" , "draw_pdf_Export ")
.Add Key := "pgm" , Item :=Array("pgm" , "Portable Graymap" , "draw_pgm_Export ")
.Add Key := "png" , Item :=Array("png" , "Portable Network Graphic" , "draw_png_Export ")
.Add Key := "ppm" , Item :=Array("ppm" , "Portable Pixelmap" , "draw_ppm_Export ")
.Add Key := "ras" , Item :=Array("ras" , "Sun Raster Image" , "draw_ras_Export ")
.Add Key := "std" , Item :=Array("std" , "OpenOffice.org 1.0 Drawing Template" , "draw_StarOffice_XML_Draw_Template ")
.Add Key := "svg" , Item :=Array("svg" , "Scalable Vector Graphics" , "draw_svg_Export ")
.Add Key := "svm" , Item :=Array("svm" , "StarView Metafile" , "draw_svm_Export ")
.Add Key := "swf" , Item :=Array("swf" , "Macromedia Flash (SWF)" , "draw_flash_Export ")
.Add Key := "sxd" , Item :=Array("sxd" , "OpenOffice.org 1.0 Drawing" , "StarOffice XML (Draw) ")
.Add Key := "sxd3" , Item :=Array("sxd" , "StarDraw 3.0" , "StarDraw 3.0 ")
.Add Key := "sxd5" , Item :=Array("sxd" , "StarDraw 5.0" , "StarDraw 5.0 ")
.Add Key := "tiff" , Item :=Array("tiff" , "Tagged Image File Format" , "draw_tif_Export ")
.Add Key := "vor" , Item :=Array("vor" , "StarDraw 5.0 Template" , "StarDraw 5.0 Vorlage ")
.Add Key := "vor3" , Item :=Array("vor" , "StarDraw 3.0 Template" , "StarDraw 3.0 Vorlage ")
.Add Key := "wmf" , Item :=Array("wmf" , "Windows Metafile" , "draw_wmf_Export ")
.Add Key := "xhtml" , Item :=Array("xhtml" , "XHTML" , "XHTML Draw File ")
.Add Key := "xpm" , Item :=Array("xpm" , "X PixMap" , "draw_xpm_Export ")
End With
With ImpressExportFilters
.Add Key := "bmp" , Item :=Array("bmp" , "Windows Bitmap" , "impress_bmp_Export ")
.Add Key := "emf" , Item :=Array("emf" , "Enhanced Metafile" , "impress_emf_Export ")
.Add Key := "eps" , Item :=Array("eps" , "Encapsulated PostScript" , "impress_eps_Export ")
.Add Key := "gif" , Item :=Array("gif" , "Graphics Interchange Format" , "impress_gif_Export ")
.Add Key := "html" , Item :=Array("html" , "HTML Document (OpenOffice.org Impress)" , "impress_html_Export ")
.Add Key := "jpg" , Item :=Array("jpg" , "Joint Photographic Experts Group" , "impress_jpg_Export ")
.Add Key := "met" , Item :=Array("met" , "OS/2 Metafile" , "impress_met_Export ")
.Add Key := "odg" , Item :=Array("odg" , "ODF Drawing (Impress)" , "impress8_draw ")
.Add Key := "odp" , Item :=Array("odp" , "ODF Presentation" , "impress8 ")
.Add Key := "otp" , Item :=Array("otp" , "ODF Presentation Template" , "impress8_template ")
.Add Key := "pbm" , Item :=Array("pbm" , "Portable Bitmap" , "impress_pbm_Export ")
.Add Key := "pct" , Item :=Array("pct" , "Mac Pict" , "impress_pct_Export ")
.Add Key := "pdf" , Item :=Array("pdf" , "Portable Document Format" , "impress_pdf_Export ")
.Add Key := "pgm" , Item :=Array("pgm" , "Portable Graymap" , "impress_pgm_Export ")
.Add Key := "png" , Item :=Array("png" , "Portable Network Graphic" , "impress_png_Export ")
.Add Key := "pot" , Item :=Array("pot" , "Microsoft PowerPoint 97/2000/XP Template" , "MS PowerPoint 97 Vorlage ")
.Add Key := "ppm" , Item :=Array("ppm" , "Portable Pixelmap" , "impress_ppm_Export ")
.Add Key := "ppt" , Item :=Array("ppt" , "Microsoft PowerPoint 97/2000/XP" , "MS PowerPoint 97 ")
.Add Key := "pwp" , Item :=Array("pwp" , "PlaceWare" , "placeware_Export ")
.Add Key := "ras" , Item :=Array("ras" , "Sun Raster Image" , "impress_ras_Export ")
.Add Key := "sda" , Item :=Array("sda" , "StarDraw 5.0 (OpenOffice.org Impress)" , "StarDraw 5.0 (StarImpress) ")
.Add Key := "sdd" , Item :=Array("sdd" , "StarImpress 5.0" , "StarImpress 5.0 ")
.Add Key := "sdd3" , Item :=Array("sdd" , "StarDraw 3.0 (OpenOffice.org Impress)" , "StarDraw 3.0 (StarImpress) ")
.Add Key := "sdd4" , Item :=Array("sdd" , "StarImpress 4.0" , "StarImpress 4.0 ")
.Add Key := "sti" , Item :=Array("sti" , "OpenOffice.org 1.0 Presentation Template" , "impress_StarOffice_XML_Impress_Template ")
.Add Key := "svg" , Item :=Array("svg" , "Scalable Vector Graphics" , "impress_svg_Export ")
.Add Key := "svm" , Item :=Array("svm" , "StarView Metafile" , "impress_svm_Export ")
.Add Key := "swf" , Item :=Array("swf" , "Macromedia Flash (SWF)" , "impress_flash_Export ")
.Add Key := "sxd" , Item :=Array("sxd" , "OpenOffice.org 1.0 Drawing (OpenOffice.org Impress)" , "impress_StarOffice_XML_Draw ")
.Add Key := "sxi" , Item :=Array("sxi" , "OpenOffice.org 1.0 Presentation" , "StarOffice XML (Impress) ")
.Add Key := "tiff" , Item :=Array("tiff" , "Tagged Image File Format" , "impress_tif_Export ")
.Add Key := "uop" , Item :=Array("uop" , "Unified Office Format presentation" , "UOF presentation ")
.Add Key := "vor" , Item :=Array("vor" , "StarImpress 5.0 Template" , "StarImpress 5.0 Vorlage ")
.Add Key := "vor3" , Item :=Array("vor" , "StarDraw 3.0 Template (OpenOffice.org Impress)" , "StarDraw 3.0 Vorlage (StarImpress) ")
.Add Key := "vor4" , Item :=Array("vor" , "StarImpress 4.0 Template" , "StarImpress 4.0 Vorlage ")
.Add Key := "vor5" , Item :=Array("vor" , "StarDraw 5.0 Template (OpenOffice.org Impress)" , "StarDraw 5.0 Vorlage (StarImpress) ")
.Add Key := "wmf" , Item :=Array("wmf" , "Windows Metafile" , "impress_wmf_Export ")
.Add Key := "xhtml" , Item :=Array("xml" , "XHTML" , "XHTML Impress File ")
.Add Key := "xpm" , Item :=Array("xpm" , "X PixMap" , "impress_xpm_Export ")
End With
With CalcExportFilters
.Add Key := "csv" , Item :=Array("csv" , "Text CSV" , "Text - txt - csv (StarCalc) ")
.Add Key := "dbf" , Item :=Array("dbf" , "dBASE" , "dBase ")
.Add Key := "dif" , Item :=Array("dif" , "Data Interchange Format" , "DIF ")
.Add Key := "html" , Item :=Array("html" , "HTML Document (OpenOffice.org Calc)" , "HTML (StarCalc) ")
.Add Key := "ods" , Item :=Array("ods" , "ODF Spreadsheet" , "calc8 ")
.Add Key := "ooxml" , Item :=Array("xml" , "Microsoft Excel 2003 XML" , "MS Excel 2003 XML ")
.Add Key := "ots" , Item :=Array("ots" , "ODF Spreadsheet Template" , "calc8_template ")
.Add Key := "pdf" , Item :=Array("pdf" , "Portable Document Format" , "calc_pdf_Export ")
.Add Key := "sdc" , Item :=Array("sdc" , "StarCalc 5.0" , "StarCalc 5.0 ")
.Add Key := "sdc3" , Item :=Array("sdc" , "StarCalc 3.0" , "StarCalc 3.0 ")
.Add Key := "sdc4" , Item :=Array("sdc" , "StarCalc 4.0" , "StarCalc 4.0 ")
.Add Key := "slk" , Item :=Array("slk" , "SYLK" , "SYLK ")
.Add Key := "stc" , Item :=Array("stc" , "OpenOffice.org 1.0 Spreadsheet Template" , "calc_StarOffice_XML_Calc_Template ")
.Add Key := "sxc" , Item :=Array("sxc" , "OpenOffice.org 1.0 Spreadsheet" , "StarOffice XML (Calc) ")
.Add Key := "uos" , Item :=Array("uos" , "Unified Office Format spreadsheet" , "UOF spreadsheet ")
.Add Key := "vor" , Item :=Array("vor" , "StarCalc 5.0 Template" , "StarCalc 5.0 Vorlage/Template ")
.Add Key := "vor3" , Item :=Array("vor" , "StarCalc 3.0 Template" , "StarCalc 3.0 Vorlage/Template ")
.Add Key := "vor4" , Item :=Array("vor" , "StarCalc 4.0 Template" , "StarCalc 4.0 Vorlage/Template ")
.Add Key := "xhtml" , Item :=Array("xhtml" , "XHTML" , "XHTML Calc File ")
.Add Key := "xls" , Item :=Array("xls" , "Microsoft Excel 97/2000/XP" , "MS Excel 97 ")
.Add Key := "xls5" , Item :=Array("xls" , "Microsoft Excel 5.0" , "MS Excel 5.0/95 ")
.Add Key := "xls95" , Item :=Array("xls" , "Microsoft Excel 95" , "MS Excel 95 ")
.Add Key := "xlt" , Item :=Array("xlt" , "Microsoft Excel 97/2000/XP Template" , "MS Excel 97 Vorlage/Template ")
.Add Key := "xlt5" , Item :=Array("xlt" , "Microsoft Excel 5.0 Template" , "MS Excel 5.0/95 Vorlage/Template ")
.Add Key := "xlt95" , Item :=Array("xlt" , "Microsoft Excel 95 Template" , "MS Excel 95 Vorlage/Template ")
End With
With WriterWebExportFilters
.Add Key := "etext" , Item :=Array("txt" , "Text Encoded (OpenOffice.org Writer/Web)" , "Text (encoded) (StarWriter/Web) ")
.Add Key := "html" , Item :=Array("html" , "HTML Document" , "HTML ")
'.Add Key := "html" , Item :=Array("html" , "HTML Document Template" , "writerweb8_writer_template ")
.Add Key := "html10" , Item :=Array("html" , "OpenOffice.org 1.0 HTML Template" , "writer_web_StarOffice_XML_Writer_Web_Template ")
.Add Key := "mediawiki" , Item :=Array("txt" , "MediaWiki" , "MediaWiki_Web ")
.Add Key := "pdf" , Item :=Array("pdf" , "PDF - Portable Document Format" , "writer_web_pdf_Export ")
.Add Key := "sdw" , Item :=Array("sdw" , "StarWriter 5.0 (OpenOffice.org Writer/Web)" , "StarWriter 5.0 (StarWriter/Web) ")
.Add Key := "sdw3" , Item :=Array("sdw" , "StarWriter 3.0 (OpenOffice.org Writer/Web)" , "StarWriter 3.0 (StarWriter/Web) ")
.Add Key := "sdw4" , Item :=Array("sdw" , "StarWriter 4.0 (OpenOffice.org Writer/Web)" , "StarWriter 4.0 (StarWriter/Web) ")
.Add Key := "text" , Item :=Array("txt" , "Text (OpenOffice.org Writer/Web)" , "Text (StarWriter/Web) ")
.Add Key := "text10" , Item :=Array("txt" , "OpenOffice.org 1.0 Text Document (OpenOffice.org Writer/Web)" , "writer_web_StarOffice_XML_Writer ")
.Add Key := "odt" , Item :=Array("txt" , "OpenOffice.org Text (OpenOffice.org Writer/Web)" , "writerweb8_writer ")
.Add Key := "vor" , Item :=Array("vor" , "StarWriter/Web 5.0 Template" , "StarWriter/Web 5.0 Vorlage/Template ")
.Add Key := "vor4" , Item :=Array("vor" , "StarWriter/Web 4.0 Template" , "StarWriter/Web 4.0 Vorlage/Template ")
End With
With DocTypeToFiltersMap
.Add Key := "com.sun.star.text.TextDocument", Item := WriterExportFilters
.Add Key := "com.sun.star.sheet.SpreadsheetDocument", Item := CalcExportFilters
.Add Key := "com.sun.star.presentation.PresentationDocument", Item :=ImpressExportFilters
.Add Key := "com.sun.star.drawing.DrawingDocument", Item := DrawExportFilters
.Add Key := "com.sun.star.text.WebDocument", Item := WriterWebExportFilters
End With
ExportFiltersInited = True
End Sub
Function FilterSaveExtension(filterDescriptor ())
FilterSaveExtension = Trim(filterDescriptor(0))
End Function
Function FilterHandler(filterDescriptor ())
FilterHandler = Trim(filterDescriptor(2))
End Function
Function GetFilter(docType, outputFormat)
Dim filters
On Error Goto MissingFilter
filters = DocTypeToFiltersMap(docType)
LogMessage "output format is " & outputFormat
GetFilter = filters(outputFormat)
Done:
Exit Function
MissingFilter:
LogMessage("No existing filters for exporting " & docType & " to " & outputFormat)
GetFilter = Null
Resume Done
End Function

View File

@ -0,0 +1,201 @@
REM ***** BASIC *****
Dim Interactive As Boolean
Dim WaitFor
Function Convert(Optional inFileURL, Optional filterSpec, Optional outFileURL)
Dim inDoc, inDocType, openParams, closeInDoc, presentationDoc
' Set Interactivity i.e., LogMessage pops up a message.
Interactive = False
WaitFor = 10
' Init dependencies
BasicLibraries.LoadLibrary("Tools")
' BasicLibraries.LoadLibrary("XrayTool")
' Setup Export filters
InitExportFilters
' Export to doc format by default
If IsMissing(filterSpec) Then
If Interactive Then
filterSpec = InputBox("Export to: ")
Else
filterSpec = "doc"
End If
End If
filterSpec = Trim(filterSpec)
closeInDoc = False
If IsMissing(inFileURL) Then
' Most likely, the Macro is run interactively. Act on
' the current document
If Not ThisComponent.HasLocation() Then
LogMessage("Document doesn't have a location")
Goto Failure
End If
inDoc = ThisComponent
inFileURL = inDoc.GetLocation()
closeInDoc = False
Else
' Load the document
On Error Goto Failure
openParams = Array(MakePropertyValue("Hidden", True),MakePropertyValue("ReadOnly", True),)
'openParams = Array()
inDoc = StarDesktop.loadComponentFromURL(inFileURL, "_blank", 0, OpenParams())
closeInDoc = True
End If
If IsMissing(outFileURL) Then
outFileURL = GetURLWithoutExtension(inFileURL)
End If
If ExportDocument(inDoc, filterSpec, outFileURL) Then
Goto Success
End If
LogMessage("filterSpec1 is " & filterSpec)
' Export didn't go through. Maybe didn't find a valid filter.
' Check whether the request is to convert a Text or a Web
' Document to a Presentation Document
inDocType = GetDocumentType(inDoc)
If (inDocType = "com.sun.star.text.TextDocument" Or _
inDocType = "com.sun.star.text.WebDocument") Then
LogMessage("Filterspec2 is " & filterSpec)
filter = GetFilter("com.sun.star.presentation.PresentationDocument", filterSpec)
If IsNull(filter) Then
LogMessage("We tried our best. Nothing more to do"
Goto Failure
Else
LogMessage("Trying to create presentation document. Found valid filter for " & filterSpec)
End If
Else
Goto Failure
End If
' Export Outline to Presentation
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(inDoc.CurrentController.Frame, ".uno:SendOutlineToStarImpress", "", 0, Array())
' Dispatch event above is aynchronous. Wait for a few seconds for the above event to finish
Wait(WaitFor * 1000)
' After the dispatch, the current component is a presentation
' document. Note that it doesn't have a location
presentationDoc = ThisComponent
If IsNull(ExportDocument(presentationDoc, filter, outFileURL)) Then
Goto Failure
Else
presentationDoc.Close(True)
End If
Success:
LogMessage("Successfully exported to " & outFileURL )
Goto Done
Failure:
LogMessage("Export failed " & outFileURL )
Goto Done
Done:
If closeInDoc Then
inDoc.Close(True)
End If
End Function
' http://codesnippets.services.openoffice.org/Writer/Writer.MergeDocs.snip
' http://user.services.openoffice.org/en/forum/viewtopic.php?f=20&t=39983
' http://user.services.openoffice.org/en/forum/viewtopic.php?f=21&t=23531
' http://wiki.services.openoffice.org/wiki/Documentation/BASIC_Guide/Files_and_Directories_%28Runtime_Library%29
Function ExportDocument(inputDoc, filterSpec, outFileURL) As Boolean
Dim inputDocType, filter
ExportDocument = False
On Error Goto Failure
inputDocType = GetDocumentType(inputDoc)
If IsArray(filterSpec) Then
' Filter is fully specified
filter = filterSpec
Else
' Filter is specified by it's name
filter = GetFilter(inputDocType, filterSpec)
End If
If InStr(outFileURL, ".") = 0 Then
outFileURL = outFileURL & "." & FilterSaveExtension(filter)
End If
LogMessage("outFileURL is " & outFileURL)
inputDoc.storeToUrl(outFileURL, Array(MakePropertyValue("FilterName", FilterHandler(filter))))
ExportDocument = True
LogMessage("Export to " & outFileURL & " succeeded")
Done:
Exit Function
Failure:
LogMessage("Export to " & outFileURL & " failed")
Resume Done
End Function
Function GetURLWithoutExtension(s As String)
Dim pos
pos = Instr(s, ".")
If pos = 0 Then
GetURLWithoutExtension = s
Else
GetURLWithoutExtension = Left(s, pos - 1)
End If
End Function
Function GetDocumentType(oDoc)
For Each docType in DocTypes
If (oDoc.supportsService(docType)) Then
GetDocumentType = docType
Exit Function
End If
Next docType
GetDocumentType = Nothing
End Function
Function MakePropertyValue(Optional sName As String, Optional sValue) As com.sun.star.beans.PropertyValue
Dim oPropertyValue As New com.sun.star.beans.PropertyValue
If Not IsMissing(sName) Then
oPropertyValue.Name = sName
EndIf
If Not IsMissing(sValue) Then
oPropertyValue.Value = sValue
EndIf
MakePropertyValue() = oPropertyValue
End Function
Sub LogMessage(message)
If Interactive Then
If Err <> 0 Then
Print "Error " & Err & ": " & Error$ & " (line : " & Erl & ")"
End If
Print message
End If
End Sub

View File

@ -1,122 +0,0 @@
;;; ob-io.el --- org-babel functions for Io evaluation
;; Copyright (C) 2012 Free Software Foundation, Inc.
;; Author: Andrzej Lichnerowicz
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Currently only supports the external execution. No session support yet.
;; :results output -- runs in scripting mode
;; :results output repl -- runs in repl mode
;;; Requirements:
;; - Io language :: http://iolanguage.org/
;; - Io major mode :: Can be installed from Io sources
;; https://github.com/stevedekorte/io/blob/master/extras/SyntaxHighlighters/Emacs/io-mode.el
;;; Code:
(require 'ob)
(require 'ob-ref)
(require 'ob-comint)
(require 'ob-eval)
(eval-when-compile (require 'cl))
(add-to-list 'org-babel-tangle-lang-exts '("io" . "io"))
(defvar org-babel-default-header-args:io '())
(defvar org-babel-io-command "io"
"Name of the command to use for executing Io code.")
(defun org-babel-execute:io (body params)
"Execute a block of Io code with org-babel. This function is
called by `org-babel-execute-src-block'"
(message "executing Io source code block")
(let* ((processed-params (org-babel-process-params params))
(session (org-babel-io-initiate-session (nth 0 processed-params)))
(vars (nth 1 processed-params))
(result-params (nth 2 processed-params))
(result-type (cdr (assoc :result-type params)))
(full-body (org-babel-expand-body:generic
body params))
(result (org-babel-io-evaluate
session full-body result-type result-params)))
(org-babel-reassemble-table
result
(org-babel-pick-name
(cdr (assoc :colname-names params)) (cdr (assoc :colnames params)))
(org-babel-pick-name
(cdr (assoc :rowname-names params)) (cdr (assoc :rownames params))))))
(defun org-babel-io-table-or-string (results)
"Convert RESULTS into an appropriate elisp value.
If RESULTS look like a table, then convert them into an
Emacs-lisp table, otherwise return the results as a string."
(org-babel-script-escape results))
(defvar org-babel-io-wrapper-method
"(
%s
) asString print
")
(defun org-babel-io-evaluate (session body &optional result-type result-params)
"Evaluate BODY in external Io process.
If RESULT-TYPE equals 'output then return standard output as a string.
If RESULT-TYPE equals 'value then return the value of the last statement
in BODY as elisp."
(when session (error "Sessions are not supported for Io. Yet."))
(case result-type
(output
(if (member "repl" result-params)
(org-babel-eval org-babel-io-command body)
(let ((src-file (org-babel-temp-file "io-")))
(progn (with-temp-file src-file (insert body))
(org-babel-eval
(concat org-babel-io-command " " src-file) "")))))
(value (let* ((src-file (org-babel-temp-file "io-"))
(wrapper (format org-babel-io-wrapper-method body)))
(with-temp-file src-file (insert wrapper))
((lambda (raw)
(if (member "code" result-params)
raw
(org-babel-io-table-or-string raw)))
(org-babel-eval
(concat org-babel-io-command " " src-file) ""))))))
(defun org-babel-prep-session:io (session params)
"Prepare SESSION according to the header arguments specified in PARAMS."
(error "Sessions are not supported for Io. Yet."))
(defun org-babel-io-initiate-session (&optional session)
"If there is not a current inferior-process-buffer in SESSION
then create. Return the initialized session. Sessions are not
supported in Io."
nil)
(provide 'ob-io)
;;; ob-io.el ends here

View File

@ -1,120 +0,0 @@
;;; ob-scala.el --- org-babel functions for Scala evaluation
;; Copyright (C) 2012 Free Software Foundation, Inc.
;; Author: Andrzej Lichnerowicz
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Currently only supports the external execution. No session support yet.
;;; Requirements:
;; - Scala language :: http://www.scala-lang.org/
;; - Scala major mode :: Can be installed from Scala sources
;; https://github.com/scala/scala-dist/blob/master/tool-support/src/emacs/scala-mode.el
;;; Code:
(require 'ob)
(require 'ob-ref)
(require 'ob-comint)
(require 'ob-eval)
(eval-when-compile (require 'cl))
(add-to-list 'org-babel-tangle-lang-exts '("scala" . "scala"))
(defvar org-babel-default-header-args:scala '())
(defvar org-babel-scala-command "scala"
"Name of the command to use for executing Scala code.")
(defun org-babel-execute:scala (body params)
"Execute a block of Scala code with org-babel. This function is
called by `org-babel-execute-src-block'"
(message "executing Scala source code block")
(let* ((processed-params (org-babel-process-params params))
(session (org-babel-scala-initiate-session (nth 0 processed-params)))
(vars (nth 1 processed-params))
(result-params (nth 2 processed-params))
(result-type (cdr (assoc :result-type params)))
(full-body (org-babel-expand-body:generic
body params))
(result (org-babel-scala-evaluate
session full-body result-type result-params)))
(org-babel-reassemble-table
result
(org-babel-pick-name
(cdr (assoc :colname-names params)) (cdr (assoc :colnames params)))
(org-babel-pick-name
(cdr (assoc :rowname-names params)) (cdr (assoc :rownames params))))))
(defun org-babel-scala-table-or-string (results)
"Convert RESULTS into an appropriate elisp value.
If RESULTS look like a table, then convert them into an
Emacs-lisp table, otherwise return the results as a string."
(org-babel-script-escape results))
(defvar org-babel-scala-wrapper-method
"(
%s
) asString print
")
(defun org-babel-scala-evaluate
(session body &optional result-type result-params)
"Evaluate BODY in external Scala process.
If RESULT-TYPE equals 'output then return standard output as a string.
If RESULT-TYPE equals 'value then return the value of the last statement
in BODY as elisp."
(when session (error "Sessions are not supported for Scala. Yet."))
(case result-type
(output
(let ((src-file (org-babel-temp-file "scala-")))
(progn (with-temp-file src-file (insert body))
(org-babel-eval
(concat org-babel-scala-command " " src-file) ""))))
(value
(let* ((src-file (org-babel-temp-file "scala-"))
(wrapper (format org-babel-scala-wrapper-method body)))
(with-temp-file src-file (insert wrapper))
((lambda (raw)
(if (member "code" result-params)
raw
(org-babel-scala-table-or-string raw)))
(org-babel-eval
(concat org-babel-scala-command " " src-file) ""))))))
(defun org-babel-prep-session:scala (session params)
"Prepare SESSION according to the header arguments specified in PARAMS."
(error "Sessions are not supported for Scala. Yet."))
(defun org-babel-scala-initiate-session (&optional session)
"If there is not a current inferior-process-buffer in SESSION
then create. Return the initialized session. Sessions are not
supported in Scala."
nil)
(provide 'ob-scala)
;;; ob-scala.el ends here

View File

@ -1,45 +0,0 @@
# -*- mode:org -*-
#+Title: Org-mode Testing
#+Property: results silent
* dependencies
The only dependency is [[http://www.emacswiki.org/emacs/ErtTestLibrary][ERT]] the Emacs testing library which ships with
Emacs24. If you are running an older version of Emacs and don't
already have ERT installed it can be installed from its old [[https://github.com/ohler/ert][git
repository]].
* non-interactive batch testing from the command line
The simplest way to run the Org-mode test suite is from the command
line with the following invocation. Note that the paths below are
relative to the base of the Org-mode directory.
#+BEGIN_SRC sh
emacs -Q --batch -l lisp/org.el -l testing/org-test.el \
--eval "(progn (org-reload) (setq org-confirm-babel-evaluate nil))" \
-f org-test-run-batch-tests
#+END_SRC
The options in the above command are explained below.
| -Q | ignores any personal configuration ensuring a vanilla Emacs instance is used |
| --batch | runs Emacs in "batch" mode with no gui and termination after execution |
| -l | loads Org-mode and the org mode test suite defined in testing/org-test.el |
| --eval | reloads Org-mode and allows evaluation of code blocks by the tests |
| -f | actually runs the tests using the `org-test-run-batch-tests' function |
* interactive testing from within Emacs
To run the Org-mode test suite from a current Emacs instance simply
load and run the test suite with the following commands.
1) First load the test suite.
#+BEGIN_SRC emacs-lisp :var here=(buffer-file-name)
(add-to-list 'load-path (file-name-directory here))
(require 'org-test)
#+END_SRC
2) Then run the test suite.
#+BEGIN_SRC emacs-lisp
(org-test-run-all-tests)
#+END_SRC
* troubleshooting
- If the value of the =org-babel-no-eval-on-ctrl-c-ctrl-c= is non-nil
then it will result in some test failure, as there are tests which
rely on this behavior.

115
testing/README.org Normal file
View File

@ -0,0 +1,115 @@
#+Title: Org-mode Testing
#+Babel: results silent
The following instructions describe how to get started using the
Org-mode test framework.
* To run the tests interactively
:PROPERTIES:
:tangle: no
:END:
1) Install the jump.el testing dependency which is included as a git
submodule in the org-mode repository. To do so run the following
git submodule commands from inside the base of the Org-mode
directory (or just execute the following code block).
#+begin_src sh
cd ..
git submodule init
git submodule update
#+end_src
2) Load the [[file:org-test.el][org-test.el]] file
#+begin_src emacs-lisp
(load-file "org-test.el")
#+end_src
3) The =org-test-jump= command is now bound to =M-C-j= in all
emacs-lisp files. Call this command from any file in the =lisp/=
directory of the org-mode repository to jump to the related test
file in the =testing/= directory. Call this functions with a
prefix argument, and the corresponding test file will be stubbed
out if it doesn't already exist.
4) Ingest the library-of-babel.org file since some tests require this.
#+begin_src emacs-lisp
(org-babel-lob-ingest "../contrib/babel/library-of-babel.org")
#+end_src
5) [[info:ert#Top][Review the ERT documentation]]
6) A number of org-mode-specific functions and macros are provided in
=org-test.el= see the [[file:org-test.el::%3B%3B%3B%20Functions%20for%20writing%20tests][;;; Functions for Writing Tests]] subsection of
that file. Some of these functions make use of example org-mode
files located in the [[file:examples][examples/]] directory.
7) Functions for loading and running the Org-mode tests are provided
in the [[file:org-test.el::%3B%3B%3B%20Load%20and%20Run%20tests][;;; Load and Run Tests]] subsection, the most important of
which are
- =org-test-load= which loads the entire Org-mode test suite
- =org-test-current-defun= which runs all tests for the current
function around point (should be called from inside of an
Org-mode elisp file)
- =org-test-run-all-tests= which runs the entire Org-mode test suite
- also note that the =ert= command can also be used to run tests
8) Load and run all tests
#+begin_src emacs-lisp
(load-file "org-test.el")
(org-babel-lob-ingest "../contrib/babel/library-of-babel.org")
(org-test-load)
(org-test-run-all-tests)
#+end_src
* To run the tests in batch mode
First tangle this file out to your desktop.
#+headers: :tangle ~/Desktop/run-org-tests.el
#+begin_src emacs-lisp :var org-dir=(expand-file-name ".." (file-name-directory (or load-file-name (buffer-file-name))))
;; add to the load path
(add-to-list 'load-path (concat org-dir "/lisp/"))
(add-to-list 'load-path (concat org-dir "/lisp/testing/"))
(add-to-list 'load-path (concat org-dir "/lisp/testing/ert/"))
;; load Org-mode
(require 'org)
;; setup the ID locations used in tests
(require 'org-id)
(org-id-update-id-locations
(list (concat org-dir "/testing/examples/babel.org")
(concat org-dir "/testing/examples/ob-C-test.org")
(concat org-dir "/testing/examples/normal.org")
(concat org-dir "/testing/examples/ob-awk-test.org")
(concat org-dir "/testing/examples/ob-octave.org")
(concat org-dir "/testing/examples/ob-fortran-test.org")
(concat org-dir "/testing/examples/ob-maxima-test.org")
(concat org-dir "/testing/examples/link-in-heading.org")
(concat org-dir "/testing/examples/links.org")))
;; ensure that the latest Org-mode is loaded
(org-reload)
;; load the test suite
(load-file (concat org-dir "/testing/org-test.el"))
;; configure Babel
(org-babel-lob-ingest (concat org-dir "/contrib/babel/library-of-babel.org"))
(org-babel-do-load-languages
'org-babel-load-languages
'((emacs-lisp . t)
(sh . t)))
(setq org-confirm-babel-evaluate nil)
;; run the test suite
(org-test-run-all-tests)
;; print the results
(with-current-buffer "*ert*"
(print (buffer-string)))
#+end_src
Then run the test suite with the following command which could use any
version of Emacs.
#+begin_src sh :results output silent
emacs --batch -Q -l ~/Desktop/run-org-tests.el
#+end_src

1
testing/contrib/lisp/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
# this file ensures that the testing/contrib/lisp directory is created by git

View File

@ -1,10 +0,0 @@
Small Org file with an include keyword.
#+BEGIN_SRC emacs-lisp :exports results
(+ 2 1)
#+END_SRC
#+INCLUDE: "include2.org"
* Heading
body

View File

@ -1 +0,0 @@
Success!

View File

@ -0,0 +1,19 @@
#+TITLE: example file with tables
#+OPTIONS: num:nil ^:nil
This is an example file for use by the Org-mode tests defined in
file:../lisp/test-org-table.el.
* simple formula
:PROPERTIES:
:ID: 563523f7-3f3e-49c9-9622-9216cc9a5d95
:END:
#+tblname: simple-formula
| 1 |
| 2 |
| 3 |
| 4 |
|----|
| 10 |
#+TBLFM: $1=vsum(@1..@-1)

View File

@ -1,436 +0,0 @@
;;; test-org-element.el --- Tests for org-element.el
;; Copyright (C) 2012 Nicolas Goaziou
;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(unless (featurep 'org-element)
(signal 'missing-test-dependency "org-element"))
;;; Tests:
;;;; Headlines
(ert-deftest test-org-element/headline-quote-keyword ()
"Test QUOTE keyword recognition."
;; Reference test.
(org-test-with-temp-text "* Headline"
(let ((org-quote-string "QUOTE"))
(should-not (org-element-property :quotedp (org-element-at-point)))))
;; Standard position.
(org-test-with-temp-text "* QUOTE Headline"
(let ((org-quote-string "QUOTE"))
(let ((headline (org-element-at-point)))
(should (org-element-property :quotedp headline))
;; Test removal from raw value.
(should (equal (org-element-property :raw-value headline) "Headline"))))
;; Case sensitivity.
(let ((org-quote-string "Quote"))
(should-not (org-element-property :quotedp (org-element-at-point)))))
;; With another keyword.
(org-test-with-temp-text "* TODO QUOTE Headline"
(let ((org-quote-string "QUOTE")
(org-todo-keywords '((sequence "TODO" "DONE"))))
(should (org-element-property :quotedp (org-element-at-point))))))
(ert-deftest test-org-element/headline-comment-keyword ()
"Test COMMENT keyword recognition."
;; Reference test.
(org-test-with-temp-text "* Headline"
(let ((org-comment-string "COMMENT"))
(should-not (org-element-property :commentedp (org-element-at-point)))))
;; Standard position.
(org-test-with-temp-text "* COMMENT Headline"
(let ((org-comment-string "COMMENT"))
(let ((headline (org-element-at-point)))
(should (org-element-property :commentedp headline))
;; Test removal from raw value.
(should (equal (org-element-property :raw-value headline) "Headline"))))
;; Case sensitivity.
(let ((org-comment-string "Comment"))
(should-not (org-element-property :commentedp (org-element-at-point)))))
;; With another keyword.
(org-test-with-temp-text "* TODO COMMENT Headline"
(let ((org-comment-string "COMMENT")
(org-todo-keywords '((sequence "TODO" "DONE"))))
(should (org-element-property :commentedp (org-element-at-point))))))
(ert-deftest test-org-element/headline-archive-tag ()
"Test ARCHIVE tag recognition."
;; Reference test.
(org-test-with-temp-text "* Headline"
(let ((org-archive-tag "ARCHIVE"))
(should-not (org-element-property :archivedp (org-element-at-point)))))
;; Single tag.
(org-test-with-temp-text "* Headline :ARCHIVE:"
(let ((org-archive-tag "ARCHIVE"))
(let ((headline (org-element-at-point)))
(should (org-element-property :archivedp headline))
;; Test tag removal.
(should-not (org-element-property :tags headline))))
(let ((org-archive-tag "Archive"))
(should-not (org-element-property :archivedp (org-element-at-point)))))
;; Multiple tags.
(org-test-with-temp-text "* Headline :test:ARCHIVE:"
(let ((org-archive-tag "ARCHIVE"))
(let ((headline (org-element-at-point)))
(should (org-element-property :archivedp headline))
;; Test tag removal.
(should (equal (org-element-property :tags headline) ":test:"))))))
;;;; Example-blocks and Src-blocks
(ert-deftest test-org-element/block-switches ()
"Test `example-block' and `src-block' switches parsing."
(let ((org-coderef-label-format "(ref:%s)"))
;; 1. Test "-i" switch.
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
(let ((element (org-element-current-element)))
(should-not (org-element-property :preserve-indent element))))
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
(let ((element (org-element-current-element)))
(should (org-element-property :preserve-indent element))))
(org-test-with-temp-text "#+BEGIN_EXAMPLE\nText.\n#+END_EXAMPLE"
(let ((element (org-element-current-element)))
(should-not (org-element-property :preserve-indent element))))
(org-test-with-temp-text "#+BEGIN_EXAMPLE -i\nText.\n#+END_EXAMPLE"
(let ((element (org-element-current-element)))
(should (org-element-property :preserve-indent element))))
;; 2. "-n -r -k" combination should number lines, retain labels but
;; not use them in coderefs.
(org-test-with-temp-text "#+BEGIN_EXAMPLE -n -r -k\nText.\N#+END_EXAMPLE"
(let ((element (org-element-current-element)))
(should (and (org-element-property :number-lines element)
(org-element-property :retain-labels element)
(not (org-element-property :use-labels element))))))
(org-test-with-temp-text
"#+BEGIN_SRC emacs-lisp -n -r -k\n(+ 1 1)\n#+END_SRC"
(let ((element (org-element-current-element)))
(should (and (org-element-property :number-lines element)
(org-element-property :retain-labels element)
(not (org-element-property :use-labels element))))))
;; 3. "-n -r" combination should number-lines remove labels and not
;; use them in coderefs.
(org-test-with-temp-text "#+BEGIN_EXAMPLE -n -r\nText.\n#+END_EXAMPLE"
(let ((element (org-element-current-element)))
(should (and (org-element-property :number-lines element)
(not (org-element-property :retain-labels element))
(not (org-element-property :use-labels element))))))
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1)\n#+END_SRC"
(let ((element (org-element-current-element)))
(should (and (org-element-property :number-lines element)
(not (org-element-property :retain-labels element))
(not (org-element-property :use-labels element))))))
;; 4. "-n" or "+n" should number lines, retain labels and use them
;; in coderefs.
(org-test-with-temp-text "#+BEGIN_EXAMPLE -n\nText.\n#+END_EXAMPLE"
(let ((element (org-element-current-element)))
(should (and (org-element-property :number-lines element)
(org-element-property :retain-labels element)
(org-element-property :use-labels element)))))
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1)\n#+END_SRC"
(let ((element (org-element-current-element)))
(should (and (org-element-property :number-lines element)
(org-element-property :retain-labels element)
(org-element-property :use-labels element)))))
(org-test-with-temp-text "#+BEGIN_EXAMPLE +n\nText.\n#+END_EXAMPLE"
(let ((element (org-element-current-element)))
(should (and (org-element-property :number-lines element)
(org-element-property :retain-labels element)
(org-element-property :use-labels element)))))
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp +n\n(+ 1 1)\n#+END_SRC"
(let ((element (org-element-current-element)))
(should (and (org-element-property :number-lines element)
(org-element-property :retain-labels element)
(org-element-property :use-labels element)))))
;; 5. No switch should not number lines, but retain labels and use
;; them in coderefs.
(org-test-with-temp-text "#+BEGIN_EXAMPLE\nText.\n#+END_EXAMPLE"
(let ((element (org-element-current-element)))
(should (and (not (org-element-property :number-lines element))
(org-element-property :retain-labels element)
(org-element-property :use-labels element)))))
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
(let ((element (org-element-current-element)))
(should (and (not (org-element-property :number-lines element))
(org-element-property :retain-labels element)
(org-element-property :use-labels element)))))
;; 6. "-r" switch only: do not number lines, remove labels, and
;; don't use labels in coderefs.
(org-test-with-temp-text "#+BEGIN_EXAMPLE -r\nText.\n#+END_EXAMPLE"
(let ((element (org-element-current-element)))
(should (and (not (org-element-property :number-lines element))
(not (org-element-property :retain-labels element))
(not (org-element-property :use-labels element))))))
(org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1)\n#+END_SRC"
(let ((element (org-element-current-element)))
(should (and (not (org-element-property :number-lines element))
(not (org-element-property :retain-labels element))
(not (org-element-property :use-labels element))))))
;; 7. Recognize coderefs with user-defined syntax.
(org-test-with-temp-text
"#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText [ref:text]\n#+END_EXAMPLE"
(let ((element (org-element-current-element)))
(should
(equal (org-element-property :label-fmt element) "[ref:%s]"))))
(org-test-with-temp-text
"#+BEGIN_SRC emacs-lisp -l \"[ref:%s]\"\n(+ 1 1) [ref:text]\n#+END_SRC"
(let ((element (org-element-current-element)))
(should
(equal (org-element-property :label-fmt element) "[ref:%s]"))))))
;;; Navigation tools.
(ert-deftest test-org-element/forward-element ()
"Test `org-element-forward' specifications."
;; 1. At EOB: should error.
(org-test-with-temp-text "Some text\n"
(goto-char (point-max))
(should-error (org-element-forward)))
;; 2. Standard move: expected to ignore blank lines.
(org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
(org-element-forward)
(should (looking-at "Second paragraph.")))
;; 3. Headline tests.
(org-test-with-temp-text "
* Head 1
** Head 1.1
*** Head 1.1.1
** Head 1.2"
;; 3.1. At an headline beginning: move to next headline at the
;; same level.
(goto-line 3)
(org-element-forward)
(should (looking-at "** Head 1.2"))
;; 3.2. At an headline beginning: move to parent headline if no
;; headline at the same level.
(goto-line 3)
(org-element-forward)
(should (looking-at "** Head 1.2")))
;; 4. Greater element tests.
(org-test-with-temp-text
"#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
;; 4.1. At a greater element: expected to skip contents.
(org-element-forward)
(should (looking-at "Outside."))
;; 4.2. At the end of greater element contents: expected to skip
;; to the end of the greater element.
(goto-line 2)
(org-element-forward)
(should (looking-at "Outside.")))
;; 5. List tests.
(org-test-with-temp-text "
- item1
- sub1
- sub2
- sub3
Inner paragraph.
- item2
Outside."
;; 5.1. At list top point: expected to move to the element after
;; the list.
(goto-line 2)
(org-element-forward)
(should (looking-at "Outside."))
;; 5.2. Special case: at the first line of a sub-list, but not at
;; beginning of line, move to next item.
(goto-line 2)
(forward-char)
(org-element-forward)
(should (looking-at "- item2"))
(goto-line 4)
(forward-char)
(org-element-forward)
(should (looking-at " - sub2"))
;; 5.3 At sub-list beginning: expected to move after the sub-list.
(goto-line 4)
(org-element-forward)
(should (looking-at " Inner paragraph."))
;; 5.4. At sub-list end: expected to move outside the sub-list.
(goto-line 8)
(org-element-forward)
(should (looking-at " Inner paragraph."))
;; 5.5. At an item: expected to move to next item, if any.
(goto-line 6)
(org-element-forward)
(should (looking-at " - sub3"))))
(ert-deftest test-org-element/backward-element ()
"Test `org-element-backward' specifications."
;; 1. At BOB (modulo some white spaces): should error.
(org-test-with-temp-text " \nParagraph."
(org-skip-whitespace)
(should-error (org-element-backward)))
;; 2. Not at the beginning of an element: move at its beginning.
(org-test-with-temp-text "Paragraph1.\n\nParagraph2."
(goto-line 3)
(end-of-line)
(org-element-backward)
(should (looking-at "Paragraph2.")))
;; 3. Headline tests.
(org-test-with-temp-text "
* Head 1
** Head 1.1
*** Head 1.1.1
** Head 1.2"
;; 3.1. At an headline beginning: move to previous headline at the
;; same level.
(goto-line 5)
(org-element-backward)
(should (looking-at "** Head 1.1"))
;; 3.2. At an headline beginning: move to parent headline if no
;; headline at the same level.
(goto-line 3)
(org-element-backward)
(should (looking-at "* Head 1"))
;; 3.3. At the first top-level headline: should error.
(goto-line 2)
(should-error (org-element-backward)))
;; 4. At beginning of first element inside a greater element:
;; expected to move to greater element's beginning.
(org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER."
(goto-line 3)
(org-element-backward)
(should (looking-at "#\\+BEGIN_CENTER")))
;; 5. List tests.
(org-test-with-temp-text "
- item1
- sub1
- sub2
- sub3
Inner paragraph.
- item2
Outside."
;; 5.1. At beginning of sub-list: expected to move to the
;; paragraph before it.
(goto-line 4)
(org-element-backward)
(should (looking-at "item1"))
;; 5.2. At an item in a list: expected to move at previous item.
(goto-line 8)
(org-element-backward)
(should (looking-at " - sub2"))
(goto-line 12)
(org-element-backward)
(should (looking-at "- item1"))
;; 5.3. At end of list/sub-list: expected to move to list/sub-list
;; beginning.
(goto-line 10)
(org-element-backward)
(should (looking-at " - sub1"))
(goto-line 15)
(org-element-backward)
(should (looking-at "- item1"))
;; 5.4. At blank-lines before list end: expected to move to top
;; item.
(goto-line 14)
(org-element-backward)
(should (looking-at "- item1"))))
(ert-deftest test-org-element/up-element ()
"Test `org-element-up' specifications."
;; 1. At BOB or with no surrounding element: should error.
(org-test-with-temp-text "Paragraph."
(should-error (org-element-up)))
(org-test-with-temp-text "* Head1\n* Head2"
(goto-line 2)
(should-error (org-element-up)))
(org-test-with-temp-text "Paragraph1.\n\nParagraph2."
(goto-line 3)
(should-error (org-element-up)))
;; 2. At an headline: move to parent headline.
(org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
(goto-line 3)
(org-element-up)
(should (looking-at "\\* Head1")))
;; 3. Inside a greater element: move to greater element beginning.
(org-test-with-temp-text
"Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
(goto-line 3)
(org-element-up)
(should (looking-at "#\\+BEGIN_CENTER")))
;; 4. List tests.
(org-test-with-temp-text "* Top
- item1
- sub1
- sub2
Paragraph within sub2.
- item2"
;; 4.1. Within an item: move to the item beginning.
(goto-line 8)
(org-element-up)
(should (looking-at " - sub2"))
;; 4.2. At an item in a sub-list: move to parent item.
(goto-line 4)
(org-element-up)
(should (looking-at "- item1"))
;; 4.3. At an item in top list: move to beginning of whole list.
(goto-line 10)
(org-element-up)
(should (looking-at "- item1"))
;; 4.4. Special case. At very top point: should move to parent of
;; list.
(goto-line 2)
(org-element-up)
(should (looking-at "\\* Top"))))
(ert-deftest test-org-element/down-element ()
"Test `org-element-down' specifications."
;; 1. Error when the element hasn't got a recursive type.
(org-test-with-temp-text "Paragraph."
(should-error (org-element-down)))
;; 2. When at a plain-list, move to first item.
(org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
(goto-line 2)
(org-element-down)
(should (looking-at " - Item 1.1")))
;; 3. Otherwise, move inside the greater element.
(org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
(org-element-down)
(should (looking-at "Paragraph"))))
(provide 'test-org-element)
;;; test-org-element.el ends here

View File

@ -1,625 +0,0 @@
;;; test-org-export.el --- Tests for org-export.el
;; Copyright (C) 2012 Nicolas Goaziou
;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
;; Released under the GNU General Public License version 3
;; see: http://www.gnu.org/licenses/gpl-3.0.html
;;;; Comments
;;; Code:
(unless (featurep 'org-export)
(signal 'missing-test-dependency "org-export"))
;;; Tests
(defmacro org-test-with-backend (backend &rest body)
"Execute body with an export back-end defined.
BACKEND is the name, as a string, of the back-end. BODY is the
body to execute. The defined back-end simply returns parsed data
as Org syntax."
(declare (debug (form body)) (indent 1))
`(flet ,(let (transcoders)
(dolist (type (append org-element-all-elements
org-element-all-objects)
transcoders)
(push `(,(intern (format "org-%s-%s" backend type))
(obj contents info)
(,(intern (format "org-element-%s-interpreter" type))
obj contents))
transcoders)))
,@body))
(ert-deftest test-org-export/parse-option-keyword ()
"Test reading all standard #+OPTIONS: items."
(should
(equal
(org-export-parse-option-keyword
"H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
*:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t")
'(:headline-levels
1 :preserve-breaks t :section-numbers t :time-stamp-file t
:with-archived-trees t :with-author t :with-creator t :with-drawers t
:with-email t :with-emphasize t :with-entities t :with-fixed-width t
:with-footnotes t :with-priority t :with-special-strings t
:with-sub-superscript t :with-toc t :with-tables t :with-tags t
:with-tasks t :with-timestamps t :with-todo-keywords t)))
;; Test some special values.
(should
(equal
(org-export-parse-option-keyword
"arch:headline creator:comment d:(\"TEST\")
^:{} toc:1 tags:not-in-toc tasks:todo num:2")
'( :section-numbers
2
:with-archived-trees headline :with-creator comment
:with-drawers ("TEST") :with-sub-superscript {} :with-toc 1
:with-tags not-in-toc :with-tasks todo))))
(ert-deftest test-org-export/get-inbuffer-options ()
"Test reading all standard export keywords."
(should
(equal
(org-test-with-temp-text "#+AUTHOR: Me, Myself and I
#+CREATOR: Idem
#+DATE: Today
#+DESCRIPTION: Testing
#+DESCRIPTION: with two lines
#+EMAIL: some@email.org
#+EXPORT_EXCLUDE_TAGS: noexport invisible
#+KEYWORDS: test
#+LANGUAGE: en
#+EXPORT_SELECT_TAGS: export
#+TITLE: Some title
#+TITLE: with spaces"
(org-export-get-inbuffer-options))
'(:author
"Me, Myself and I" :creator "Idem" :date "Today"
:description "Testing\nwith two lines" :email "some@email.org"
:exclude-tags ("noexport" "invisible") :keywords "test" :language "en"
:select-tags ("export") :title "Some title with spaces"))))
(ert-deftest test-org-export/define-macro ()
"Try defining various Org macro using in-buffer #+MACRO: keyword."
;; Parsed macro.
(should (equal (org-test-with-temp-text "#+MACRO: one 1"
(org-export-get-inbuffer-options))
'(:macro-one ("1"))))
;; Evaled macro.
(should (equal (org-test-with-temp-text "#+MACRO: two (eval (+ 1 1))"
(org-export-get-inbuffer-options))
'(:macro-two "(eval (+ 1 1))")))
;; Incomplete macro.
(should-not (org-test-with-temp-text "#+MACRO: three"
(org-export-get-inbuffer-options)))
;; Macro with newline character.
(should (equal (org-test-with-temp-text "#+MACRO: four a\\nb"
(org-export-get-inbuffer-options))
'(:macro-four ("a\nb"))))
;; Macro with protected newline character.
(should (equal (org-test-with-temp-text "#+MACRO: five a\\\\nb"
(org-export-get-inbuffer-options))
'(:macro-five ("a\\nb"))))
;; Recursive macro.
(org-test-with-temp-text "#+MACRO: six 6\n#+MACRO: seven 1 + {{{six}}}"
(should
(equal
(org-export-get-inbuffer-options)
'(:macro-six
("6")
:macro-seven
("1 + " (macro (:key "six" :value "{{{six}}}" :args nil :begin 5 :end 14
:post-blank 0))))))))
(ert-deftest test-org-export/handle-options ()
"Test if export options have an impact on output."
;; Test exclude tags.
(org-test-with-temp-text "* Head1 :noexport:"
(org-test-with-backend "test"
(should
(equal (org-export-as 'test nil nil nil '(:exclude-tags ("noexport")))
""))))
;; Test include tags.
(org-test-with-temp-text "
* Head1
** Sub-Head1.1 :export:
*** Sub-Head1.1.1
* Head2"
(org-test-with-backend "test"
(should
(string-match
"\\* Head1\n\\*\\* Sub-Head1.1[ \t]+:export:\n\\*\\*\\* Sub-Head1.1.1\n"
(org-export-as 'test nil nil nil '(:select-tags ("export")))))))
;; Test mixing include tags and exclude tags.
(org-test-with-temp-text "
* Head1 :export:
** Sub-Head1 :noexport:
** Sub-Head2
* Head2 :noexport:
** Sub-Head1 :export:"
(org-test-with-backend "test"
(should
(string-match
"\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
(org-export-as
'test nil nil nil
'(:select-tags ("export") :exclude-tags ("noexport")))))))
;; Ignore tasks.
(let ((org-todo-keywords '((sequence "TODO" "DONE"))))
(org-test-with-temp-text "* TODO Head1"
(org-test-with-backend "test"
(should (equal (org-export-as 'test nil nil nil '(:with-tasks nil))
"")))))
(let ((org-todo-keywords '((sequence "TODO" "DONE"))))
(org-test-with-temp-text "* TODO Head1"
(org-test-with-backend "test"
(should (equal (org-export-as 'test nil nil nil '(:with-tasks t))
"* TODO Head1\n")))))
;; Archived tree.
(org-test-with-temp-text "* Head1 :archive:"
(let ((org-archive-tag "archive"))
(org-test-with-backend "test"
(should
(equal (org-export-as 'test nil nil nil '(:with-archived-trees nil))
"")))))
(org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
(let ((org-archive-tag "archive"))
(org-test-with-backend "test"
(should
(string-match
"\\* Head1[ \t]+:archive:"
(org-export-as 'test nil nil nil
'(:with-archived-trees headline)))))))
(org-test-with-temp-text "* Head1 :archive:"
(let ((org-archive-tag "archive"))
(org-test-with-backend "test"
(should
(string-match
"\\`\\* Head1[ \t]+:archive:\n\\'"
(org-export-as 'test nil nil nil '(:with-archived-trees t)))))))
;; Drawers.
(let ((org-drawers '("TEST")))
(org-test-with-temp-text ":TEST:\ncontents\n:END:"
(org-test-with-backend "test"
(should (equal (org-export-as 'test nil nil nil '(:with-drawers nil))
"")))))
(let ((org-drawers '("TEST")))
(org-test-with-temp-text ":TEST:\ncontents\n:END:"
(org-test-with-backend "test"
(should (equal (org-export-as 'test nil nil nil '(:with-drawers t))
":TEST:\ncontents\n:END:\n"))))))
(ert-deftest test-org-export/comment-tree ()
"Test if export process ignores commented trees."
(let ((org-comment-string "COMMENT"))
(org-test-with-temp-text "* COMMENT Head1"
(org-test-with-backend "test"
(should (equal (org-export-as 'test) ""))))))
(ert-deftest test-org-export/export-scope ()
"Test all export scopes."
(org-test-with-temp-text "
* Head1
** Head2
text
*** Head3"
(org-test-with-backend "test"
;; Subtree.
(forward-line 3)
(should (equal (org-export-as 'test 'subtree) "text\n*** Head3\n"))
;; Visible.
(goto-char (point-min))
(forward-line)
(org-cycle)
(should (equal (org-export-as 'test nil 'visible) "* Head1\n"))
;; Body only.
(flet ((org-test-template (body info) (format "BEGIN\n%sEND" body)))
(should (equal (org-export-as 'test nil nil 'body-only)
"* Head1\n** Head2\ntext\n*** Head3\n"))
(should (equal (org-export-as 'test)
"BEGIN\n* Head1\n** Head2\ntext\n*** Head3\nEND")))
;; Region.
(goto-char (point-min))
(forward-line 3)
(transient-mark-mode 1)
(push-mark (point) t t)
(goto-char (point-at-eol))
(should (equal (org-export-as 'test) "text\n")))))
(ert-deftest test-org-export/export-snippet ()
"Test export snippets transcoding."
(org-test-with-temp-text "@test{A}@t{B}"
(org-test-with-backend "test"
(flet ((org-test-export-snippet
(snippet contents info)
(when (eq (org-export-snippet-backend snippet) 'test)
(org-element-property :value snippet))))
(let ((org-export-snippet-translation-alist nil))
(should (equal (org-export-as 'test) "A\n")))
(let ((org-export-snippet-translation-alist '(("t" . "test"))))
(should (equal (org-export-as 'test) "AB\n")))))))
(ert-deftest test-org-export/expand-include ()
"Test file inclusion in an Org buffer."
;; Full insertion with recursive inclusion.
(org-test-with-temp-text
(format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir)
(org-export-expand-include-keyword)
(should (equal (buffer-string)
"Small Org file with an include keyword.
#+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
Success!
* Heading
body\n")))
;; Localized insertion.
(org-test-with-temp-text
(format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
org-test-dir)
(org-export-expand-include-keyword)
(should (equal (buffer-string)
"Small Org file with an include keyword.\n")))
;; Insertion with constraints on headlines level.
(org-test-with-temp-text
(format
"* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
org-test-dir)
(org-export-expand-include-keyword)
(should (equal (buffer-string) "* Top heading\n** Heading\nbody\n")))
;; Inclusion within an example block.
(org-test-with-temp-text
(format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
org-test-dir)
(org-export-expand-include-keyword)
(should
(equal
(buffer-string)
"#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
;; Inclusion within a src-block.
(org-test-with-temp-text
(format
"#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
org-test-dir)
(org-export-expand-include-keyword)
(should (equal (buffer-string)
"#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
(ert-deftest test-org-export/user-ignore-list ()
"Test if `:ignore-list' accepts user input."
(org-test-with-backend "test"
(flet ((skip-note-head
(data backend info)
;; Ignore headlines with the word "note" in their title.
(org-element-map
data 'headline
(lambda (headline)
(when (string-match "\\<note\\>"
(org-element-property :raw-value headline))
(org-export-ignore-element headline info)))
info)
data))
;; Install function in parse tree filters.
(let ((org-export-filter-parse-tree-functions '(skip-note-head)))
(org-test-with-temp-text "* Head1\n* Head2 (note)\n"
(should (equal (org-export-as 'test) "* Head1\n")))))))
;; Footnotes
(ert-deftest test-org-export/footnotes ()
"Test footnotes specifications."
(let ((org-footnote-section nil))
;; 1. Read every type of footnote.
(org-test-with-temp-text
"Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
(let* ((tree (org-element-parse-buffer))
(info (org-combine-plists
(org-export-initial-options) '(:with-footnotes t))))
(setq info (org-combine-plists
info (org-export-collect-tree-properties tree info 'test)))
(should
(equal
'((1 . "A") (2 . "B") (3 . "C") (4 . "D"))
(org-element-map
tree 'footnote-reference
(lambda (ref)
(let ((def (org-export-get-footnote-definition ref info)))
(cons (org-export-get-footnote-number ref info)
(if (eq (org-element-property :type ref) 'inline) (car def)
(car (org-element-contents
(car (org-element-contents def))))))))
info)))))
;; 2. Test nested footnotes order.
(org-test-with-temp-text
"Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
(let* ((tree (org-element-parse-buffer))
(info (org-combine-plists
(org-export-initial-options) '(:with-footnotes t))))
(setq info (org-combine-plists
info (org-export-collect-tree-properties tree info 'test)))
(should
(equal
'((1 . "fn:1") (2 . "fn:2") (3 . "fn:3") (4))
(org-element-map
tree 'footnote-reference
(lambda (ref)
(when (org-export-footnote-first-reference-p ref info)
(cons (org-export-get-footnote-number ref info)
(org-element-property :label ref))))
info)))))
;; 3. Test nested footnote in invisible definitions.
(org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
;; Hide definitions.
(narrow-to-region (point) (point-at-eol))
(let* ((tree (org-element-parse-buffer))
(info (org-combine-plists
(org-export-initial-options) '(:with-footnotes t))))
(setq info (org-combine-plists
info (org-export-collect-tree-properties tree info 'test)))
;; Both footnotes should be seen.
(should
(= (length (org-export-collect-footnote-definitions tree info)) 2))))
;; 4. Test footnotes definitions collection.
(org-test-with-temp-text "Text[fn:1:A[fn:2]] [fn:3].
\[fn:2] B [fn:3] [fn::D].
\[fn:3] C."
(let ((tree (org-element-parse-buffer))
(info (org-combine-plists
(org-export-initial-options) '(:with-footnotes t))))
(setq info (org-combine-plists
info (org-export-collect-tree-properties tree info 'test)))
(should (= (length (org-export-collect-footnote-definitions tree info))
4))))))
;;; Links
(ert-deftest test-org-export/fuzzy-links ()
"Test fuzz link export specifications."
;; 1. Links to invisible (keyword) targets should be ignored.
(org-test-with-temp-text
"Paragraph.\n#+TARGET: Test\n[[Test]]"
(let* ((tree (org-element-parse-buffer))
(info (org-combine-plists (org-export-initial-options))))
(setq info (org-combine-plists
info (org-export-collect-tree-properties tree info 'test)))
(should-not
(org-element-map
tree 'link
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info))))
;; 2. Link to an headline should return headline's number.
(org-test-with-temp-text
"Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
(let* ((tree (org-element-parse-buffer))
(info (org-combine-plists (org-export-initial-options))))
(setq info (org-combine-plists
info (org-export-collect-tree-properties tree info 'test)))
(should
;; Note: Headline's number is in fact a list of numbers.
(equal '(2)
(org-element-map
tree 'link
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info t)))))
;; 3. Link to a target in an item should return item's number.
(org-test-with-temp-text
"- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
(let* ((tree (org-element-parse-buffer))
(info (org-combine-plists (org-export-initial-options))))
(setq info (org-combine-plists
info (org-export-collect-tree-properties tree info 'test)))
(should
;; Note: Item's number is in fact a list of numbers.
(equal '(1 2)
(org-element-map
tree 'link
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info t)))))
;; 4. Link to a target in a footnote should return footnote's
;; number.
(org-test-with-temp-text
"Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
(let* ((tree (org-element-parse-buffer))
(info (org-combine-plists (org-export-initial-options))))
(setq info (org-combine-plists
info (org-export-collect-tree-properties tree info 'test)))
(should
(equal '(2 3)
(org-element-map
tree 'link
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info)))))
;; 5. Link to a named element should return sequence number of that
;; element.
(org-test-with-temp-text
"#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
(let* ((tree (org-element-parse-buffer))
(info (org-combine-plists (org-export-initial-options))))
(setq info (org-combine-plists
info (org-export-collect-tree-properties tree info 'test)))
(should
(= 2
(org-element-map
tree 'link
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info t)))))
;; 6. Link to a target not within an item, a table, a footnote
;; reference or definition should return section number.
(org-test-with-temp-text
"* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
(let* ((tree (org-element-parse-buffer))
(info (org-combine-plists (org-export-initial-options))))
(setq info (org-combine-plists
info (org-export-collect-tree-properties tree info 'test)))
(should
(equal '(2)
(org-element-map
tree 'link
(lambda (link)
(org-export-get-ordinal
(org-export-resolve-fuzzy-link link info) info)) info t))))))
(defun test-org-export/resolve-coderef ()
"Test `org-export-resolve-coderef' specifications."
(let ((org-coderef-label-format "(ref:%s)"))
;; 1. A link to a "-n -k -r" block returns line number.
(org-test-with-temp-text
"#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
(let ((tree (org-element-parse-buffer)))
(should
(= (org-export-resolve-coderef "coderef" `(:parse-tree ,tree)) 1))))
(org-test-with-temp-text
"#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
(let ((tree (org-element-parse-buffer)))
(should
(= (org-export-resolve-coderef "coderef" `(:parse-tree ,tree)) 1))))
;; 2. A link to a "-n -r" block returns line number.
(org-test-with-temp-text
"#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
(let ((tree (org-element-parse-buffer)))
(should
(= (org-export-resolve-coderef "coderef" `(:parse-tree ,tree)) 1))))
(org-test-with-temp-text
"#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
(let ((tree (org-element-parse-buffer)))
(should
(= (org-export-resolve-coderef "coderef" `(:parse-tree ,tree)) 1))))
;; 3. A link to a "-n" block returns coderef.
(org-test-with-temp-text
"#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
(let ((tree (org-element-parse-buffer)))
(should
(equal (org-export-resolve-coderef "coderef" `(:parse-tree ,tree))
"coderef"))))
(org-test-with-temp-text
"#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
(let ((tree (org-element-parse-buffer)))
(should
(equal (org-export-resolve-coderef "coderef" `(:parse-tree ,tree))
"coderef"))))
;; 4. A link to a "-r" block returns line number.
(org-test-with-temp-text
"#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
(let ((tree (org-element-parse-buffer)))
(should
(= (org-export-resolve-coderef "coderef" `(:parse-tree ,tree)) 1))))
(org-test-with-temp-text
"#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
(let ((tree (org-element-parse-buffer)))
(should
(= (org-export-resolve-coderef "coderef" `(:parse-tree ,tree)) 1))))
;; 5. A link to a block without a switch returns coderef.
(org-test-with-temp-text
"#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
(let ((tree (org-element-parse-buffer)))
(should
(equal (org-export-resolve-coderef "coderef" `(:parse-tree ,tree))
"coderef"))))
(org-test-with-temp-text
"#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
(let ((tree (org-element-parse-buffer)))
(should
(equal (org-export-resolve-coderef "coderef" `(:parse-tree ,tree))
"coderef"))))
;; 6. Correctly handle continued line numbers. A "+n" switch
;; should resume numbering from previous block with numbered
;; lines, ignoring blocks not numbering lines in the process.
;; A "-n" switch resets count.
(org-test-with-temp-text "
#+BEGIN_EXAMPLE -n
Text.
#+END_EXAMPLE
#+BEGIN_SRC emacs-lisp
\(- 1 1)
#+END_SRC
#+BEGIN_SRC emacs-lisp +n -r
\(+ 1 1) (ref:addition)
#+END_SRC
#+BEGIN_EXAMPLE -n -r
Another text. (ref:text)
#+END_EXAMPLE"
(let* ((tree (org-element-parse-buffer))
(info `(:parse-tree ,tree)))
(should (= (org-export-resolve-coderef "addition" info) 2))
(should (= (org-export-resolve-coderef "text" info) 1))))
;; 7. Recognize coderef with user-specified syntax.
(org-test-with-temp-text
"#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
(let ((tree (org-element-parse-buffer)))
(should (equal (org-export-resolve-coderef "text" `(:parse-tree ,tree))
"text"))))))
;;; Src-block and example-block
(ert-deftest test-org-export/unravel-code ()
"Test `org-export-unravel-code' function."
(let ((org-coderef-label-format "(ref:%s)"))
;; 1. Code without reference.
(org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
(should (equal (org-export-unravel-code (org-element-current-element))
'("(+ 1 1)\n"))))
;; 2. Code with reference.
(org-test-with-temp-text
"#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
(should (equal (org-export-unravel-code (org-element-current-element))
'("(+ 1 1)\n" (1 . "test")))))
;; 3. Code with user-defined reference.
(org-test-with-temp-text
"#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
(should (equal (org-export-unravel-code (org-element-current-element))
'("(+ 1 1)\n" (1 . "test")))))
;; 4. Code references keys are relative to the current block.
(org-test-with-temp-text "
#+BEGIN_EXAMPLE -n
\(+ 1 1)
#+END_EXAMPLE
#+BEGIN_EXAMPLE +n
\(+ 2 2)
\(+ 3 3) (ref:one)
#+END_EXAMPLE"
(goto-line 5)
(should (equal (org-export-unravel-code (org-element-current-element))
'("(+ 2 2)\n(+ 3 3)\n" (2 . "one")))))
;; 5. Free up comma-protected lines.
;;
;; 5.1. In an Org source block, every line is protected.
(org-test-with-temp-text
"#+BEGIN_SRC org\n,* Test\n,# comment\n,Text\n#+END_SRC"
(should (equal (org-export-unravel-code (org-element-current-element))
'("* Test\n# comment\nText\n"))))
;; 5.2. In other blocks, only headlines, comments and keywords are
;; protected.
(org-test-with-temp-text
"#+BEGIN_EXAMPLE\n,* Headline\n, * Not headline\n,Keep\n#+END_EXAMPLE"
(should (equal (org-export-unravel-code (org-element-current-element))
'("* Headline\n, * Not headline\n,Keep\n"))))))
(provide 'test-org-export)
;;; test-org-export.el end here