mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-29 05:01:49 +00:00
Make HTML export work.
The key is the new copier script lib/scripts/ext_copy.py. Usage: ext_copy.py [-e ext1,ext2,...] <from file> <to file> Given a <from file> and <to file>, it will copy all files in the directory in which from_file is found that have the extensions given in the -e option, or all files in that directory if no such argument is given. So, for example, we can do: python ext_copy.py -e png,html,css /path/from/file.html /path/to/file.html and all html, png, and css files in /path/from/ will be copied to the (possibly new) directory /path/to/file.html.LyXconv/. The -t option determines the extension added to the output filename passed to the script ($$o, in the copier definition), the default being "LyXconv". If just . is given, then no extension is added. Other changes: * configure.py: added appropriate copier definitions for html and wordhtml formats, as well as for the Program pseudo-format. * lib/Makefile.am and development/scons/scons_manifest.py: add ext_copy.py. * lib/doc/Customization.lyx: update documentation. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18791 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
054a35c9a1
commit
954be90e11
@ -2729,6 +2729,7 @@ lib_scripts_files = Split('''
|
|||||||
clean_dvi.py
|
clean_dvi.py
|
||||||
convertDefault.py
|
convertDefault.py
|
||||||
date.py
|
date.py
|
||||||
|
ext_copy.py
|
||||||
fen2ascii.py
|
fen2ascii.py
|
||||||
fig2pdftex.py
|
fig2pdftex.py
|
||||||
fig2pstex.py
|
fig2pstex.py
|
||||||
|
@ -1017,6 +1017,7 @@ dist_scripts_PYTHON = \
|
|||||||
scripts/clean_dvi.py \
|
scripts/clean_dvi.py \
|
||||||
scripts/convertDefault.py \
|
scripts/convertDefault.py \
|
||||||
scripts/date.py \
|
scripts/date.py \
|
||||||
|
scripts/ext_copy.py \
|
||||||
scripts/fen2ascii.py \
|
scripts/fen2ascii.py \
|
||||||
scripts/fig2pdftex.py \
|
scripts/fig2pdftex.py \
|
||||||
scripts/fig2pstex.py \
|
scripts/fig2pstex.py \
|
||||||
|
@ -347,8 +347,19 @@ def checkConverterEntries():
|
|||||||
checkProg('an MS Word -> LaTeX converter', ['wvCleanLatex $$i $$o'],
|
checkProg('an MS Word -> LaTeX converter', ['wvCleanLatex $$i $$o'],
|
||||||
rc_entry = [ r'\converter word latex "%%" ""' ])
|
rc_entry = [ r'\converter word latex "%%" ""' ])
|
||||||
#
|
#
|
||||||
checkProg('a LaTeX -> MS Word converter', ["htlatex $$i 'html,word' 'symbol/!' '-cvalidate'"],
|
path, htmlconv = checkProg('a LaTeX -> HTML converter', ['htlatex $$i', 'tth -t -e2 -L$$b < $$i > $$o', \
|
||||||
|
'latex2html -no_subdir -split 0 -show_section_numbers $$i', 'hevea -s $$i'],
|
||||||
|
rc_entry = [ r'\converter latex html "%%" "needaux"' ])
|
||||||
|
if htmlconv == 'htlatex' or htmlconv == 'latex2html':
|
||||||
|
addToRC(r'''\copier html "python -tt $$s/scripts/ext_copy.py -e html,png,css $$i $$o"''')
|
||||||
|
else:
|
||||||
|
addToRC(r'''\copier html "python -tt $$s/scripts/ext_copy.py $$i $$o"''')
|
||||||
|
|
||||||
|
#
|
||||||
|
path, htmlconv = checkProg('a LaTeX -> MS Word converter', ["htlatex $$i 'html,word' 'symbol/!' '-cvalidate'"],
|
||||||
rc_entry = [ r'\converter latex wordhtml "%%" "needaux"' ])
|
rc_entry = [ r'\converter latex wordhtml "%%" "needaux"' ])
|
||||||
|
if htmlconv == 'htlatex':
|
||||||
|
addToRC(r'''\copier wordhtml "python -tt $$s/scripts/ext_copy.py -e html,png,css $$i $$o"''')
|
||||||
#
|
#
|
||||||
checkProg('an OpenOffice.org -> LaTeX converter', ['w2l -clean $$i'],
|
checkProg('an OpenOffice.org -> LaTeX converter', ['w2l -clean $$i'],
|
||||||
rc_entry = [ r'\converter sxw latex "%%" ""' ])
|
rc_entry = [ r'\converter sxw latex "%%" ""' ])
|
||||||
@ -358,10 +369,6 @@ def checkConverterEntries():
|
|||||||
#
|
#
|
||||||
checkProg('a LaTeX -> Open Document converter', ['oolatex $$i', 'oolatex.sh $$i'],
|
checkProg('a LaTeX -> Open Document converter', ['oolatex $$i', 'oolatex.sh $$i'],
|
||||||
rc_entry = [ r'\converter latex odt "%%" "latex"' ])
|
rc_entry = [ r'\converter latex odt "%%" "latex"' ])
|
||||||
#
|
|
||||||
#FIXME Looking for the commands needed to make oolatex output sxw instad of odt...
|
|
||||||
#checkProg('a LaTeX -> OpenOffice.org (sxw) converter', ['oolatex $$i', 'oolatex.sh $$i'],
|
|
||||||
# rc_entry = [ r'\converter latex odt "%%" "latex"' ])
|
|
||||||
# On windows it is called latex2rt.exe
|
# On windows it is called latex2rt.exe
|
||||||
checkProg('a LaTeX -> RTF converter', ['latex2rtf -p -S -o $$o $$i', 'latex2rt -p -S -o $$o $$i'],
|
checkProg('a LaTeX -> RTF converter', ['latex2rtf -p -S -o $$o $$i', 'latex2rt -p -S -o $$o $$i'],
|
||||||
rc_entry = [ r'\converter latex rtf "%%" "needaux"' ])
|
rc_entry = [ r'\converter latex rtf "%%" "needaux"' ])
|
||||||
@ -429,9 +436,6 @@ def checkConverterEntries():
|
|||||||
\converter agr ppm "gracebat -hardcopy -printfile $$o -hdevice PNM $$i 2>/dev/null" ""''',
|
\converter agr ppm "gracebat -hardcopy -printfile $$o -hdevice PNM $$i 2>/dev/null" ""''',
|
||||||
''])
|
''])
|
||||||
#
|
#
|
||||||
checkProg('a LaTeX -> HTML converter', ['htlatex $$i', 'tth -t -e2 -L$$b < $$i > $$o', \
|
|
||||||
'latex2html -no_subdir -split 0 -show_section_numbers $$i', 'hevea -s $$i'],
|
|
||||||
rc_entry = [ r'\converter latex html "%%" "needaux"' ])
|
|
||||||
#
|
#
|
||||||
path, lilypond = checkProg('a LilyPond -> EPS/PDF/PNG converter', ['lilypond'])
|
path, lilypond = checkProg('a LilyPond -> EPS/PDF/PNG converter', ['lilypond'])
|
||||||
if (lilypond != ''):
|
if (lilypond != ''):
|
||||||
@ -537,6 +541,7 @@ def checkOtherEntries():
|
|||||||
addToRC(r'''\copier fig "python -tt $$s/scripts/fig_copy.py $$i $$o"
|
addToRC(r'''\copier fig "python -tt $$s/scripts/fig_copy.py $$i $$o"
|
||||||
\copier pstex "python -tt $$s/scripts/tex_copy.py $$i $$o $$l"
|
\copier pstex "python -tt $$s/scripts/tex_copy.py $$i $$o $$l"
|
||||||
\copier pdftex "python -tt $$s/scripts/tex_copy.py $$i $$o $$l"
|
\copier pdftex "python -tt $$s/scripts/tex_copy.py $$i $$o $$l"
|
||||||
|
\copier program "python -tt $$s/scripts/ext_copy.py $$i $$o"
|
||||||
''')
|
''')
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#LyX 1.5.0svn created this file. For more info see http://www.lyx.org/
|
#LyX 1.5.0svn created this file. For more info see http://www.lyx.org/
|
||||||
\lyxformat 271
|
\lyxformat 274
|
||||||
\begin_document
|
\begin_document
|
||||||
\begin_header
|
\begin_header
|
||||||
\textclass book
|
\textclass book
|
||||||
@ -1699,6 +1699,11 @@ s.
|
|||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
\begin_layout Section
|
\begin_layout Section
|
||||||
|
\begin_inset LatexCommand label
|
||||||
|
name "sec:converters-etc"
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
Converters, Formats, and Copiers
|
Converters, Formats, and Copiers
|
||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
@ -1961,7 +1966,7 @@ P
|
|||||||
references:Copiers
|
references:Copiers
|
||||||
\family default
|
\family default
|
||||||
dialog.
|
dialog.
|
||||||
Since all conversions from one Format to another take place in a temporary
|
Since all conversions from one Format to another take place in LyX's temporary
|
||||||
directory, it is sometimes necessary to modify a file before copying it
|
directory, it is sometimes necessary to modify a file before copying it
|
||||||
to the temporary directory in order that the conversion may be performed.
|
to the temporary directory in order that the conversion may be performed.
|
||||||
\begin_inset Foot
|
\begin_inset Foot
|
||||||
@ -1977,6 +1982,77 @@ For example, the file may refer to other files---images, for example---using
|
|||||||
|
|
||||||
This is done by the Copier: It copies a file to (or from) the temporary
|
This is done by the Copier: It copies a file to (or from) the temporary
|
||||||
directory and may modify it in the process.
|
directory and may modify it in the process.
|
||||||
|
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Standard
|
||||||
|
Copiers may also be used for other purposes.
|
||||||
|
For example, if appropriate converters are found, LyX will automatically
|
||||||
|
install copiers for the html and wordhtml formats.
|
||||||
|
When these formats are exported, the copier sees to it that not just the
|
||||||
|
main HTML file but various associated files (style files, images, and the
|
||||||
|
like) are also copied, and all these files are written to a subdirectory
|
||||||
|
of the directory in which the original LyX file was found.
|
||||||
|
The copier may of course be customized.
|
||||||
|
The optional -e argument takes a comma-separated list of extensions to
|
||||||
|
be copied; if it is omitted, all files will be copied.
|
||||||
|
The -t argument determines the extension added to the generated directory.
|
||||||
|
By default, it is
|
||||||
|
\begin_inset Quotes eld
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
LyXconv
|
||||||
|
\begin_inset Quotes erd
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
, so HTML generated from
|
||||||
|
\family typewriter
|
||||||
|
/path/to/filename.lyx
|
||||||
|
\family default
|
||||||
|
will end up in
|
||||||
|
\family typewriter
|
||||||
|
/path/to/filename.html.LyXconv
|
||||||
|
\family default
|
||||||
|
.
|
||||||
|
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Standard
|
||||||
|
The definitions of the copiers may use four variables:
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout List
|
||||||
|
\labelwidthstring 00.00.0000
|
||||||
|
$$s The LyX system directory (e.g.,
|
||||||
|
\family typewriter
|
||||||
|
/usr/share/lyx
|
||||||
|
\family default
|
||||||
|
).
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout List
|
||||||
|
\labelwidthstring 00.00.0000
|
||||||
|
$$i The input file
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout List
|
||||||
|
\labelwidthstring 00.00.0000
|
||||||
|
$$o The output file
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout List
|
||||||
|
\labelwidthstring 00.00.0000
|
||||||
|
$$l The `LaTeX name'
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Standard
|
||||||
|
The latter is to be given in a form suitable for inclusion in a LaTeX
|
||||||
|
\family typewriter
|
||||||
|
|
||||||
|
\backslash
|
||||||
|
include
|
||||||
|
\family default
|
||||||
|
command and is relevant only when exporting files suitable for such inclusion.
|
||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
\begin_layout Subsection
|
\begin_layout Subsection
|
||||||
|
88
lib/scripts/ext_copy.py
Normal file
88
lib/scripts/ext_copy.py
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
#! /usr/bin/env python
|
||||||
|
# -*- coding: iso-8859-1 -*-
|
||||||
|
|
||||||
|
# file ext_copy.py
|
||||||
|
# This file is part of LyX, the document processor.
|
||||||
|
# Licence details can be found in the file COPYING.
|
||||||
|
|
||||||
|
# author Richard Heck
|
||||||
|
|
||||||
|
# Full author contact details are available in file CREDITS
|
||||||
|
|
||||||
|
# Usage:
|
||||||
|
# ext_copy.py [-e ext1,ext2,...] <from file> <to file>
|
||||||
|
|
||||||
|
# This script is to be used as a "copier" script in the sense needed by
|
||||||
|
# the converter definitions. Given a <from file> and <to file>, it will copy
|
||||||
|
# all files in the directory in which from_file is found that have the
|
||||||
|
# extensions given in the -e argument, or all files in that directory if no
|
||||||
|
# such argument is given. So, for example, we can do:
|
||||||
|
# python ext_copy.py -e png,html,css /path/from/file.html /path/to/file.html
|
||||||
|
# and all html, png, and css files in /path/from/ will be copied to the
|
||||||
|
# (possibly new) directory /path/to/file.html.LyXconv/.
|
||||||
|
# The -t argument determines the extension added, the default being "LyXconv".
|
||||||
|
# If just . is given, no extension is added.
|
||||||
|
|
||||||
|
# KNOWN BUG: This script is not aware of generated subdirectories.
|
||||||
|
|
||||||
|
import os, sys, getopt
|
||||||
|
from lyxpreview_tools import error
|
||||||
|
|
||||||
|
|
||||||
|
def usage(prog_name):
|
||||||
|
return "Usage: %s [-e extensions] [-t target extension] <from file> <to file>" % prog_name
|
||||||
|
|
||||||
|
|
||||||
|
def main(argv):
|
||||||
|
progname = argv[0]
|
||||||
|
|
||||||
|
exts = [] #list of extensions for which we're checking
|
||||||
|
targext = "LyXconv" #extension for target directory
|
||||||
|
opts, args = getopt.getopt(sys.argv[1:], "e:t:")
|
||||||
|
for o, v in opts:
|
||||||
|
if o == "-e":
|
||||||
|
exts = v.split(',')
|
||||||
|
if o == "-t":
|
||||||
|
targext = v
|
||||||
|
|
||||||
|
# input directory
|
||||||
|
if len(args) != 2:
|
||||||
|
error(usage(progname))
|
||||||
|
abs_from_file = args[0]
|
||||||
|
if not os.path.isabs(abs_from_file):
|
||||||
|
error("%s is not an absolute file name.\n%s" % abs_from_file, usage(progname))
|
||||||
|
from_dir = os.path.dirname(abs_from_file)
|
||||||
|
|
||||||
|
# output directory
|
||||||
|
to_dir = args[1]
|
||||||
|
if targext != '.':
|
||||||
|
to_dir += "." + targext
|
||||||
|
if not os.path.isabs(to_dir):
|
||||||
|
error("%s is not an absolute file name.\n%s" % to_dir, usage(progname))
|
||||||
|
|
||||||
|
# try to create the output directory if it doesn't exist
|
||||||
|
if not os.path.isdir(to_dir):
|
||||||
|
try:
|
||||||
|
os.makedirs(to_dir)
|
||||||
|
except:
|
||||||
|
error("Unable to create %s" % to_dir)
|
||||||
|
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
# copy all matching files in from_dir to to_dir
|
||||||
|
for file in os.listdir(from_dir):
|
||||||
|
junk, ext = os.path.splitext(os.path.basename(file))
|
||||||
|
ext = ext.lower()[1:] #strip the leading dot
|
||||||
|
try:
|
||||||
|
# if exts is empty we ignore it
|
||||||
|
# otherwise check if the extension is in the list
|
||||||
|
not exts or exts.index(ext)
|
||||||
|
except:
|
||||||
|
continue #not found
|
||||||
|
from_file = os.path.join(from_dir, file)
|
||||||
|
to_file = os.path.join(to_dir, file)
|
||||||
|
shutil.copy(from_file, to_file)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main(sys.argv)
|
Loading…
Reference in New Issue
Block a user