developer tip

doc / docx 파일을 마크 다운 또는 구조화 된 텍스트로 어떻게 변환 할 수 있습니까?

optionbox 2021. 1. 7. 07:54
반응형

doc / docx 파일을 마크 다운 또는 구조화 된 텍스트로 어떻게 변환 할 수 있습니까?


Markdown 또는 유사한 텍스트 .doc또는 .docx파일을 변환 할 프로그램이나 워크 플로가 있습니까?

추신 : 이상적으로 consolas는 MS Word 문서 의 특정 글꼴 (예 :)이으로 렌더링 되는 옵션을 환영합니다 text-code: ```....```.


Pandoc은 docx에서 마크 다운으로의 직접 변환을 지원합니다.

pandoc -f docx -t markdown foo.docx -o foo.markdown

여러 마크 다운 형식이 지원됩니다.

-t gfm (GitHub-Flavored Markdown)  
-t markdown_mmd (MultiMarkdown)  
-t markdown (pandoc’s extended Markdown)  
-t markdown_strict (original unextended Markdown)  
-t markdown_phpextra (PHP Markdown Extra)  
-t commonmark (CommonMark Markdown)  

Mammoth 는 Word to HTML 변환기로 가장 잘 알려져 있지만 이제 Markdown writer 모듈을 지원 합니다. 마지막으로 확인했을 때 Mammoth Markdown 지원은 아직 초기 단계 였으므로 일부 기능이 지원되지 않을 수 있습니다. 평소처럼 ... 최신 세부 사항은 웹 사이트를 확인하십시오.

설치

Javascript 버전을 사용하려면 ... NodeJS 를 설치 한 다음 Mammoth를 설치하십시오.

npm install -g mammoth

명령 줄

Word 문서를 Markdown으로 변환하는 명령 줄 ...

mammoth document.docx --output-format=markdown

API

Markdown으로 변환 할 NodeJS API ...

var mammoth = require("mammoth");
mammoth.convertToMarkdown({path: "path/to/document.docx"});

풍모:

Mammoth Markdown 작성자는 현재 다음을 지원합니다.

  • 목록 (번호 및 글 머리 기호)
  • 연결
  • 굵게, 기울임 꼴과 같은 글꼴 스타일
  • 이미지

Mammoth 명령 줄 도구 및 API는 여러 언어 로 이식되었습니다 .

마크 다운 없음 (2016 년 5 월) :

Markdown 사용 :


stackoverflow에 대해이 질문을 했으므로 다른 답변을 포함 한 프로그래밍 방식 또는 명령 줄 솔루션을 원할 것입니다.

그러나 대체 솔루션은 Microsoft Word 용 Writage Markdown 플러그인 을 사용하는 입니다.

Writage는 Word를 Markdown WYSIWYG 편집기로 바꾸므로 Microsoft Word에서 일반적으로 문서를 편집하는 것처럼 Markdown 파일을 열고 편집 할 수 있습니다. 또한 다른 변환기없이 Word 문서를 Markdown 파일로 저장할 수 있습니다.

내부적으로, Writage는 사용 Pandoc 당신은 또한 작업이 플러그인 설치해야한다는 점을.

현재 다음 마크 다운 요소를 지원합니다.

  • 제목
  • 목록 (번호 및 글 머리 기호)
  • 연결
  • 굵게, 기울임 꼴과 같은 글꼴 스타일
  • 테이블
  • 각주

이는 명령 줄 도구를 설치하거나 실행할 필요가없고 가장 익숙한 것을 고수하기 때문에 많은 최종 사용자에게 이상적인 솔루션 일 수 있습니다.


당신이 사용할 수있는 마크 다운으로 말씀을 한 번에 변환하기 (루비 보석). 변환은 다음과 같이 간단 할 수 있습니다.

$ gem install word-to-markdown
$ w2m path/to/document.docx

LibreOffice를 통해 문서를 라우팅하지만 상대적인 글꼴 크기를 기반으로하는 의미 제목에도 최선을 다합니다.

드래그 앤 드롭으로 변환하는 것만 큼 간단한 호스팅 버전있습니다.


변환 도구 사용

이전 파일을 "대량"으로 변환하려고합니까?
그렇다면 변환 도구가 필요합니다. 마크 다운 편집기는 한 번에 하나의 파일에서 대화식으로 작동합니다. 설계에 의한 변환 도구는 파일을 " 대량 "으로 변환합니다 .


그러나 어떤 변환 도구?

이 세 가지를 테스트했습니다. (1)-Pandoc / (2)-Mammoth / (3)-w2m

Windows 사용자 : 아래에서 Windows 사용자 를위한 'Writage'Linux
/ macOS / Cygwin을 참조하십시오 .


Pandoc

많은 테스트를 거친 후에는 pandoc이러한 종류의 작업에 가장 적합한 도구입니다.

통사론: pandoc -f[rom] docx -t[o] gfm --wrap=preserve somedoc.docx -o[utput] somedoc.md

내가 처음에 깨닫지 못한 것은 pandocGithub Flavored Markdown (GFM) 테이블 (pandoc에서 "pipe_tables"라고 함)을 내보내려면 GFM pandoc 형식을 사용해야한다는 것입니다.

MultiMarkdown

Multimarkdown메타 데이터, 목차, 각주 및 YAML과 같은 기능이 더 풍부한 마크 다운 형식입니다. 그러나 gfm또한 훌륭하고 Github의 표준입니다.


Pandoc 지원 형식

-t gfm (GitHub-Flavored Markdown)  
-t markdown_mmd (MultiMarkdown)  
-t markdown (pandoc’s extended Markdown)  
-t markdown_strict (original unextended Markdown)  
-t markdown_phpextra (PHP Markdown Extra)  
-t commonmark (CommonMark Markdown)  


-t docx (docx)  
-t html (HTML)  
-t latex (LaTeX)  
-t mediawiki (MediaWiki markup)  

-t textile (Textile)  
-t rst (reStructuredText)  
-t docbook (DocBook)  
-t t2t (txt2tags)  
-t odt (ODT)  
-t epub (EPUB)  
-t opml (OPML)  
-t org (Emacs Org mode)  
-t twiki (TWiki markup)  
-t haddock (Haddock markup)  



WYSIWYG 편집자

If exporting markdown --> docx and NOT docx --> markdown, a WYSIWYG editor like Typora (cross platform) or iA Writer (macOS) will have access to superior fonts for better screen readabilty, including emoji's for example, and other unicode characters. But "on-mass" exports to pdf using pandoc will print just fine too.


Writage MS Word Extension

Writage (an MS Word extension) does a reasonable job of reading markdown files in Microsoft Word. You can then save it as a .docx file. Alternatively, use somehting like Markdown Viewer for Chrome and copy paste into word. This will keep the formatting theme you've chosen in Markdown Viewer.

Writage - MS Word extension


UPDATE:

Papersize: A4 or US Letter

Pandoc's default behaviour is to output to US Letter. Fix it by setting the geometry variable:

pandoc -s -V geometry:a4paper -o outfile.pdf infile.md


NOTE: pandoc uses LaTeX templates to format to PDF so you may need to install the LaTeX package for your OS if that command does not work out of the box.

Instructions at LaTeX Installation


Word to Markdown might be worth a shot, or the procedure described here using Calibre and Pandoc via HTMLZ, here's a bash script they use:

#!/bin/bash
mkdir temp
cp $1 temp
cd temp
ebook-convert $1 output.htmlz
unzip output.htmlz
cd ..
pandoc -f html -t markdown -o output.md temp/index.html
rm -R temp

From here:

unoconv -f html test.docx
pandoc -f html -t markdown -o test.md test.html

You can convert Word documents from within MS Word to Markdown using this Visual Basic Script:

https://gist.github.com/hawkrives/2305254

Follow the instructions under "To use the code" to create a new Macro in Word.

Note: This converts the currently open Word document ato Markdown, which removes all the Word formatting (headings, lists, etc.). First save the Word document you plan to converts, and then save the document again as a new document before running the macro. This way you can always go back to the original Word document to make changes.

There are more examples of Word to markdown VB scripts here:

https://www.mediawiki.org/wiki/Microsoft_Word_Macros


If you're using Linux, try Pandoc (first convert .doc/.docx into html with LibreOffice or something and then run it).

On Windows (or if Pandoc doesn't work), you can try this website (online demo, you can download it): Markdownify


For bulleted lists you can paste a list into Sublime Text and use multiselect ( tested ) or find and replace ( not tested ) to replace eg the proprietary MS Word characters with -, -- etc

This doesn't work with headings but it may be possible to use a similar technique with other elements.


Here's an open-source web application built in Ruby to do this exact thing: https://word2md.com

ReferenceURL : https://stackoverflow.com/questions/16383237/how-can-doc-docx-files-be-converted-to-markdown-or-structured-text

반응형