-
-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Always make word counts etc. available in odt output as variables #2033
Comments
Does the Open Document format support this? |
Uh..., yes, 'User Field' seems to be the right field type for this. Supports string and float, apparently.
The definition is saved even if the field is not used in the document. |
As far as I know, most of this is generated dynamically by LibreOffice. See this Insert >Field dialog:
Actually, the right place for this is the meta.xml file in the odt zip archive. Here you can create the fields in the With Python, I use this template: _META_XML = '''<?xml version="1.0" encoding="utf-8"?>
<office:document-meta xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:grddl="http://www.w3.org/2003/g/data-view#" office:version="1.2">
<office:meta>
<meta:generator>novxlib</meta:generator>
<dc:title>$Title</dc:title>
<dc:description>$Summary</dc:description>
<dc:subject></dc:subject>
<meta:keyword></meta:keyword>
<meta:initial-creator>$Author</meta:initial-creator>
<dc:creator></dc:creator>
<meta:creation-date>${Datetime}Z</meta:creation-date>
<dc:date></dc:date>
</office:meta>
</office:document-meta>
'''
|
Isn't this the document word count, as opposed to the manuscript word count? Maybe I didn't specify the use case well enough, but modifying a generated document by adding/changing a title page shouldn't change the manuscript word count. If you intend to split a fine hair, you could also be interested in the word count without headings etc.
Yes! |
As we know from NaNoWriMo, each word processor seems to calculate a different word count for the same text. Edit: Incidentally, a static word count property would soon be outdated if the odt document were still being worked on. |
Agreed!
Agreed!
The supposed workflow here is editing the manuscript with novelWriter only. Changes to the odt after the build should be as few as absolutely necessary. |
I'll try to summarize this enhancement request:
The second part adds few benefits if novelWriter's |
What's the point of the meta values? These are already populated by novelWriter. The following meta data is set: # Office Meta Data
xMeta = ET.SubElement(self._xMeta, _mkTag("meta", "creation-date"))
xMeta.text = timeStamp
xMeta = ET.SubElement(self._xMeta, _mkTag("meta", "generator"))
xMeta.text = f"novelWriter/{__version__}"
xMeta = ET.SubElement(self._xMeta, _mkTag("meta", "initial-creator"))
xMeta.text = self._project.data.author
xMeta = ET.SubElement(self._xMeta, _mkTag("meta", "editing-cycles"))
xMeta.text = str(self._project.data.saveCount)
# Format is: PnYnMnDTnHnMnS
# https://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#duration
eT = self._project.data.editTime
xMeta = ET.SubElement(self._xMeta, _mkTag("meta", "editing-duration"))
xMeta.text = f"P{eT//86400:d}DT{eT%86400//3600:d}H{eT%3600//60:d}M{eT%60:d}S"
# Dublin Core Meta Data
xMeta = ET.SubElement(self._xMeta, _mkTag("dc", "title"))
xMeta.text = self._project.data.name
xMeta = ET.SubElement(self._xMeta, _mkTag("dc", "date"))
xMeta.text = timeStamp
xMeta = ET.SubElement(self._xMeta, _mkTag("dc", "creator"))
xMeta.text = self._project.data.author |
Anyway, the fields were trivial to add. I just made all fields recorded available, and prefixed them with "Manuscript": It only took a few lines of code. if self._counts:
xFields = ET.Element(_mkTag("text", "user-field-decls"))
for key, value in self._counts.items():
ET.SubElement(xFields, _mkTag("text", "user-field-decl"), attrib={
_mkTag("office", "value-type"): "float",
_mkTag("office", "value"): str(value),
_mkTag("text", "name"): f"Manuscript{key[:1].upper()}{key[1:]}",
})
self._xText.insert(0, xFields) |
When odt output is created, it would be nice to have the metadata available as variables for use with templates and LibreOffice Writer's 'Insert Field' command: word counts (text/headings), paragraph count, character count, build date, build settings name, author, title, etc.
This feature should be always enabled (without a configuration option in the build settings).
Inspired by #2023, #2024
The text was updated successfully, but these errors were encountered: