Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docx Writer: Implement user-defined styles. #3070

Merged
merged 12 commits into from Aug 15, 2016
Merged

Docx Writer: Implement user-defined styles. #3070

merged 12 commits into from Aug 15, 2016

Conversation

jkr
Copy link
Collaborator

@jkr jkr commented Aug 14, 2016

This supersedes #3069.

This is an RFC PR (I'll be writing to the mailing list) and shouldn't be considered final.

This would allow users to dynamically control the styles on docx output. People could either write divs by hand or -- more what I had in mind -- script to control indentation or whatever.

A few notes:

  1. This requires divs, since we can't add attributes to arbitrary blocks. Unlike the previous PR, it will affect all blocks within the div, since the styles will cascade appropriately.
  2. We use a k-v pair in the attribute: the value associated with the key "docx-style" will be passed through. (This takes precedence over the "references" class.)
  3. As before, the styles won't do anything if they're not already in your reference.docx. In fact, they'll just show up as "Normal Text", and convert to that upon saving. So this is only useful if you have a reference.docx already.

Divs with a "docx-style" key in the attributes will apply the
corresponding key to the contained blocks.
@jgm
Copy link
Owner

jgm commented Aug 15, 2016

This looks good to me. You might add to this PR some changes to MANUAL.txt, so this is documented, and of course tests.

@jkr
Copy link
Collaborator Author

jkr commented Aug 15, 2016

Bikeshedding: what do you think the key should be? I have docx-style in there right now, but it seems like something that could be equally usable for ODT and any other future binary formats (PPT,) would be preferable. custom-style, pandoc-style both come to mind.

The safest solution -- if we don't want to step on people's pass-through HTML -- would be to have a default key (custom-style, pandoc-style, whatever) and an option --custom-style-key, so that people could reset it if they for some reason wanted to reserve our key. But this does add yet another option, and could easily be added later if it ever becomes an issue.

We want to be able to inject these into our styles.xml.
We're going to want `getMap` in the Docx Writer.
This injects new dynamic paragraph properties to be into the style
file. Nothing occurs if the prop already exists in the style file.
This enables dynamic styling on spans. It uses the same prefix as we
used on divs ("docx-style" for the moment). It does not yet inject the
style into styles.xml.
@jkr
Copy link
Collaborator Author

jkr commented Aug 15, 2016

Some new changes: it works with spans as well, and will also inject styles into style.xml if they don't exist. If they are already there, it doesn't mess with them.

Use "custom-style" instead of "docx-style." This allows it to be used in
other formats like ODT in the future.
Sometimes we will want to get back something different than we started
with in a round-trip test. This allows for that, and makes the perfect
roundtrip a special case.
This just tests whether a custom style with a recognizable
style (italic etc, defined in a reference.docx) will roundtrip back to
that format (i.e., whether `<span custom-style="Emphasized">` will
roundtrip to `Emph`). The custom styles are defined in the
`custom-style-reference.docx` included in the docx dir.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants