{"action":"created","issue":{"url":"https://api.github.com/repos/jgm/pandoc/issues/2573","repository_url":"https://api.github.com/repos/jgm/pandoc","labels_url":"https://api.github.com/repos/jgm/pandoc/issues/2573/labels{/name}","comments_url":"https://api.github.com/repos/jgm/pandoc/issues/2573/comments","events_url":"https://api.github.com/repos/jgm/pandoc/issues/2573/events","html_url":"https://github.com/jgm/pandoc/issues/2573","id":120362690,"number":2573,"title":"Horizontal Rule in DOCX","user":{"login":"DaveJarvis","id":2131950,"avatar_url":"https://avatars.githubusercontent.com/u/2131950?v=3","gravatar_id":"","url":"https://api.github.com/users/DaveJarvis","html_url":"https://github.com/DaveJarvis","followers_url":"https://api.github.com/users/DaveJarvis/followers","following_url":"https://api.github.com/users/DaveJarvis/following{/other_user}","gists_url":"https://api.github.com/users/DaveJarvis/gists{/gist_id}","starred_url":"https://api.github.com/users/DaveJarvis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DaveJarvis/subscriptions","organizations_url":"https://api.github.com/users/DaveJarvis/orgs","repos_url":"https://api.github.com/users/DaveJarvis/repos","events_url":"https://api.github.com/users/DaveJarvis/events{/privacy}","received_events_url":"https://api.github.com/users/DaveJarvis/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-04T09:20:15Z","updated_at":"2016-05-04T15:17:06Z","closed_at":null,"body":"Consider the following text:\r\n\r\n```markdown\r\n# Chapter\r\n## Section\r\n\r\nSection text.\r\n\r\n---\r\n\r\nDivided section.\r\n\r\n## Second Section\r\n# Second Chapter\r\n```\r\n\r\nThis generates a document that, when opened in LibreOffice 5.x, resembles:\r\n\r\n![example-output](https://cloud.githubusercontent.com/assets/2131950/11585959/90b255d0-9a24-11e5-8da9-864f12d9c85c.png)\r\n\r\nThe [Haskell code](http://hackage.haskell.org/package/pandoc-1.15.1/docs/src/Text-Pandoc-Writers-Docx.html) that generates the XML looks like:\r\n\r\n```haskell\r\nblockToOpenXML _ HorizontalRule = do\r\n  setFirstPara\r\n  return [\r\n    mknode \"w:p\" [] $ mknode \"w:r\" [] $ mknode \"w:pict\" []\r\n    $ mknode \"v:rect\" [(\"style\",\"width:0;height:1.5pt\"),\r\n                       (\"o:hralign\",\"center\"),\r\n                       (\"o:hrstd\",\"t\"),(\"o:hr\",\"t\")] () ]\r\n```\r\n\r\nThe `width:0` does not appear to be correct.\r\n\r\nNote that typical manuscript format (for submitting to publishers) prefers a centered `#` character to a horizontal rule. If there was a way to configure how a horizontal rule should be presented (e.g., centered, text, or line width and thickness) from the command-line (when generating DOCX or RTF files), that would be quite useful.\r\n\r\nFor example:\r\n\r\n    pandoc --reference-docx=reference.docx -s --hr-width 50% --hr-height .5pt\r\n    pandoc --reference-docx=reference.docx -s --hr-text \"* * *\" --hr-justify right\r\n    pandoc --reference-docx=reference.docx -s --hr-text \"#\" --hr-justify center\r\n\r\nThe `hr` could equally be `horizontal-rule` or `rule`.\r\n\r\nThe XML to center a hashmark, for example:\r\n\r\n```xml\r\n<w:p>\r\n  <w:pPr>\r\n    <w:pStyle w:val=\"Normal\"/>\r\n    <w:jc w:val=\"center\"/>\r\n    <w:rPr></w:rPr>\r\n  </w:pPr>\r\n  <w:r>\r\n    <w:rPr></w:rPr>\r\n    <w:t>#</w:t>\r\n  </w:r>\r\n</w:p>\r\n```\r\n\r\nIt's possible to write a shell script to work around the issue, but it's a fairly cumbersome hack:\r\n\r\n```bash\r\n#!/bin/bash\r\n\r\n# Filename to update\r\nMANUSCRIPT=filename.docx\r\n\r\nchmod 644 $MANUSCRIPT\r\n\r\n# Use the reference document (template) to create the DOCX version.\r\npandoc \\\r\n  --reference-docx=reference.docx \\\r\n  -o $MANUSCRIPT \\\r\n  -s *.md\r\n\r\nWORKING_DIR=/tmp/replacement/\r\nDOC_DIR=$WORKING_DIR/word\r\n\r\nrm -rf $WORKING_DIR\r\nmkdir -p $WORKING_DIR\r\n\r\n# Modify the DOCX file directly.\r\nunzip $MANUSCRIPT -d $WORKING_DIR\r\n\r\n# Replace the horizontal rule with a centered hashmark.\r\nsed -e 's!<w:p><w:r><w:pict><v:rect style=\"width:0;height:1.5pt\" o:hralign=\"center\" o:hrstd=\"t\" o:hr=\"t\" /></w:pict></w:r></w:p>!<w:p><w:pPr><w:pStyle w:val=\"Normal\"/><w:jc w:val=\"center\"/><w:rPr></w:rPr></w:pPr><w:r><w:rPr></w:rPr><w:t>\\#</w:t></w:r></w:p>!g' $DOC_DIR/document.xml > $DOC_DIR/document.xml.tmp && mv $DOC_DIR/document.xml.tmp $DOC_DIR/document.xml\r\n\r\n# Repack the document.\r\npushd $WORKING_DIR\r\nzip -9 -r /tmp/$MANUSCRIPT .\r\npopd\r\nrm -rf $WORKING_DIR\r\n\r\n# Replace the existing manuscript with the revised version.\r\nmv /tmp/$MANUSCRIPT .\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/jgm/pandoc/issues/comments/216898099","html_url":"https://github.com/jgm/pandoc/issues/2573#issuecomment-216898099","issue_url":"https://api.github.com/repos/jgm/pandoc/issues/2573","id":216898099,"user":{"login":"Jmuccigr","id":615115,"avatar_url":"https://avatars.githubusercontent.com/u/615115?v=3","gravatar_id":"","url":"https://api.github.com/users/Jmuccigr","html_url":"https://github.com/Jmuccigr","followers_url":"https://api.github.com/users/Jmuccigr/followers","following_url":"https://api.github.com/users/Jmuccigr/following{/other_user}","gists_url":"https://api.github.com/users/Jmuccigr/gists{/gist_id}","starred_url":"https://api.github.com/users/Jmuccigr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jmuccigr/subscriptions","organizations_url":"https://api.github.com/users/Jmuccigr/orgs","repos_url":"https://api.github.com/users/Jmuccigr/repos","events_url":"https://api.github.com/users/Jmuccigr/events{/privacy}","received_events_url":"https://api.github.com/users/Jmuccigr/received_events","type":"User","site_admin":false},"created_at":"2016-05-04T15:17:06Z","updated_at":"2016-05-04T15:17:06Z","body":"Nothing zip about Word's xml, I messed around a tiny bit with the document.xml file and found that deleting that last style setting, `,(\"o:hr\",\"t\")` in the code, and giving the width an actual value like `50pt` creates something, but it's not centered. Creating a rectangle directly leaves very different xml."}}