{"action":"created","issue":{"url":"https://api.github.com/repos/dolanmiu/docx/issues/143","repository_url":"https://api.github.com/repos/dolanmiu/docx","labels_url":"https://api.github.com/repos/dolanmiu/docx/issues/143/labels{/name}","comments_url":"https://api.github.com/repos/dolanmiu/docx/issues/143/comments","events_url":"https://api.github.com/repos/dolanmiu/docx/issues/143/events","html_url":"https://github.com/dolanmiu/docx/pull/143","id":357086662,"node_id":"MDExOlB1bGxSZXF1ZXN0MjEzMTg0NzIz","number":143,"title":"use .dotx files as an initial template for a new (document) file","user":{"login":"amitm02","id":1888927,"node_id":"MDQ6VXNlcjE4ODg5Mjc=","avatar_url":"https://avatars2.githubusercontent.com/u/1888927?v=4","gravatar_id":"","url":"https://api.github.com/users/amitm02","html_url":"https://github.com/amitm02","followers_url":"https://api.github.com/users/amitm02/followers","following_url":"https://api.github.com/users/amitm02/following{/other_user}","gists_url":"https://api.github.com/users/amitm02/gists{/gist_id}","starred_url":"https://api.github.com/users/amitm02/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amitm02/subscriptions","organizations_url":"https://api.github.com/users/amitm02/orgs","repos_url":"https://api.github.com/users/amitm02/repos","events_url":"https://api.github.com/users/amitm02/events{/privacy}","received_events_url":"https://api.github.com/users/amitm02/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":17,"created_at":"2018-09-05T06:43:57Z","updated_at":"2018-09-18T00:49:38Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/dolanmiu/docx/pulls/143","html_url":"https://github.com/dolanmiu/docx/pull/143","diff_url":"https://github.com/dolanmiu/docx/pull/143.diff","patch_url":"https://github.com/dolanmiu/docx/pull/143.patch"},"body":"I've started to implement a way to use an existing template document for a new (document) file.\r\nPlease see demo27.\r\n\r\nI've concentrated on it being able to init the headers and footers of a new document from a template. But i think it be can easily extended in import other parts (e.g styles/numbering etc').\r\n\r\nI think it can be a great uplift to the library. Currently the library does an amazing job at generating .docx files (JS -> docx). This could be the beginning of building the other direction of the bride:  (docx -> JS)\r\n\r\n**IMPORTANT: although the demos seems to work. But the update will fail test/linting/pretty runs. I hope i can have help with that.**\r\n\r\nHow it works:\r\n\r\n- /src/importDocx/importDocx.ts, includes a new class that accept a \".dotx\" Buffer, parse it, and returns a simpler version of a template \"File\" class: \r\n```\r\ninterface TemplateDocument {\r\n    currentRelationshipId : number;\r\n    headers : {type : HeaderReferenceType, header : HeaderWrapper}[],\r\n    footers : {type : FooterReferenceType, footer : FooterWrapper}[],\r\n}\r\n```\r\n\r\n- The parsing is \"narrow\" and not \"wide\", in the sense i've only extracted headers and footers. Making the parsing \"wide\" to the point in generate a full \"File\" class (e.g styles) can be an future feature.\r\n\r\n- The parsing is \"shallow\" and not \"deep\", in the sense that the content under an extracted \"HeaderWrapper\", is stored as the base \"XmlComponents\" and not as the extended version (e.g \"Paragraph\", \"Text\"). Making the parsing \"deep\" can be an future feature.\r\n\r\n- What the above means is that it is possible the modify the headers/footers on the top level (e.g add a new paragraph), but modifying an inner XML in them (e.g an exciting paragraph) is not yet possible.\r\n\r\n-  The \"File\" constructor, can accept this \"TemplateDocument \" object as a property in \"options\" parameter, and it will build a new document have having those headers/footers (including media that they may have).\r\n\r\nSome other changes that was needed to make the library more align with possible template inputs:\r\n- A section can have multiple headers/footers (possible types: default, first, even).\r\n- Each header/footer has its own \"media\" (images).\r\n\r\nOne last note: Parsing an exiting .docx files they way is a good method to revel hidden bugs. For example, while testing the new code' I've found that the new File that was generated from a template was corrupted. The reason was that the line in prepForXml() \r\n`\".filter((comp) => comp)\" // Exclude null, undefined, and empty strings`\r\nwas filtering the value 0 in addition to null and undefined. That resulted in a invalid xml for docx.\r\n\r\n\r\n\r\n \r\n\r\n"},"comment":{"url":"https://api.github.com/repos/dolanmiu/docx/issues/comments/422217004","html_url":"https://github.com/dolanmiu/docx/pull/143#issuecomment-422217004","issue_url":"https://api.github.com/repos/dolanmiu/docx/issues/143","id":422217004,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMjIxNzAwNA==","user":{"login":"dolanmiu","id":2917613,"node_id":"MDQ6VXNlcjI5MTc2MTM=","avatar_url":"https://avatars1.githubusercontent.com/u/2917613?v=4","gravatar_id":"","url":"https://api.github.com/users/dolanmiu","html_url":"https://github.com/dolanmiu","followers_url":"https://api.github.com/users/dolanmiu/followers","following_url":"https://api.github.com/users/dolanmiu/following{/other_user}","gists_url":"https://api.github.com/users/dolanmiu/gists{/gist_id}","starred_url":"https://api.github.com/users/dolanmiu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dolanmiu/subscriptions","organizations_url":"https://api.github.com/users/dolanmiu/orgs","repos_url":"https://api.github.com/users/dolanmiu/repos","events_url":"https://api.github.com/users/dolanmiu/events{/privacy}","received_events_url":"https://api.github.com/users/dolanmiu/received_events","type":"User","site_admin":false},"created_at":"2018-09-18T00:49:38Z","updated_at":"2018-09-18T00:49:38Z","author_association":"OWNER","body":"Good news is, I fixed the tests, bad news is, it needs `.filter((comp) => comp !== null);` to work\r\n\r\nFinding a way to fix"}}
{"actor":{"display_login":"dolanmiu"}}