我正在尝试将大量用 Markdown 编写的文档迁移到 Google 文档中,以便我们的营销部门可以使用它。
是否有一种使用 appscript/Google Docs Api 的机制可以导入文件并使用预定义模板将其转换为 Google 文档? 例如 H1s 将映射到标题等
对于许多开发人员来说,最简单的方法很可能不需要新工具(如果您愿意进行一些手动粘贴):
只需使用 Visual Studio Code。
当然,如果有大量文档,您会需要比这更自动化的东西。
一个建议:使用 Pandoc 将 Markdown 转换为 docx,然后使用 Google Drive API 导入到 Google Docs。
您还可以使用 Google Drive 网络界面来完成此操作:
pandoc MyFile.md -f markdown -t odt -s -o MyFile.odt
我刚刚偶然发现了一种非常简单的方法,可能适合您的需求。
在 github 中,我打开了一个 ReadMe.md 文件,该文件在浏览器中呈现为富文本。我从浏览器复制它并将其粘贴到新的 Google 文档中。
Voila:Google 文档保留了标题、项目符号等。我不能保证它对链接和其他更高级的降价操作的作用,但这是一种快速入门的方法。
使用 pandoc
docx
格式而不是 odt
。 Google Docs 原生处理 MS Office 文件,因此我发现使用这种方法可以更好地保留格式。
修改步骤:
pandoc MyFile.md -f markdown -t docx -s -o MyFile.docx
MyFile.docx
到您的 Google 云端硬盘文件夹MyFile.docx
MyFile.docx
我不知道有什么工具或库可以直接从 Markdown 转换为 Google 文档。
也许您可以将 Markdown 转换为与 Google Docs 兼容的中间格式(可行的格式包括 .docx、.docm、.dot、.dotx、.dotm、.html、纯文本 (.txt)、.rtf 和 .odt)以及然后从那里开始。
您只需要找到一个可以将 Markdown 转换为其中一种格式并批量处理文件的工具(也许某些命令行实用程序可以帮助实现这一点)。
#!/bin/bash
# Create the "converted" directory if it doesn't already exist
if [ ! -d "converted" ]; then
mkdir "converted"
fi
# Find all markdown files in the current directory and its subdirectories
find . -name "*.md" | while read filename; do
# Use pandoc to convert the file to a .docx file
pandoc "$filename" -o "${filename%.*}.docx"
# Create the same directory structure under "converted" as the original file
dir=$(dirname "$filename")
mkdir -p "converted/$dir"
# Move the converted file to the "converted" directory
mv "${filename%.*}.docx" "converted/$dir"
done
有 Google Docs 插件 Markdown to Docs ... 可以将 Markdown 转换为 Google Docs。
由于 Gdoc 格式,它有其局限性,但在其他方面工作得很好。
我为此创建了一个小脚本,现在位于 github 上。您几乎可以剪切和粘贴。我需要这个解决方案,但找不到任何解决方案,所以我使用谷歌应用程序脚本制作了它。 https://github.com/brandhorse/google-docs-markdown希望这对一些人有帮助。干杯。