I am trying to migrate a load of documentation which was written in markdown into a Google Doc so it can be used by our marketing department.
Is there a mechanism using appscript/ Google Docs Api that I can import a file and convert it to a Google Doc using a predefined template?
Eg H1s will map to Title, etc
One suggestion: use Pandoc to convert Markdown to docx, then import to Google Docs using the Google Drive API.
You can also accomplish this using the Google Drive web interface:
Convert markdown to ODT (or some other intermediate) using pandoc: pandoc MyFile.md -f markdown -t odt -s -o MyFile.odt
Move the ODT file into your Google Drive folder.
Right-click the ODT file (in the web version of Drive) and press "Open With -> Google Docs".
Google Drive will now create a new Google Doc, with contents matching the ODT file, and open it for you.
No add-ons needed
I just stumbled upon a really simple approach that may suit your needs.
In github, I opened a ReadMe.md file, rendered in the browser as rich text. I copied it from the browser and pasted it into a new Google Doc.
Voila: Google Docs preserved the headings, bullets, etc. I can't vouch for what it does with links and other fancier markdown ops, but it was a quick way to get started.
Easiest way that most likely requires no new tooling for many developers (if you're willing to do some manual pasting):
Just use Visual Studio Code.
Paste text into the editor.
At bottom right, select markdown as language.
Top right, click the preview button.
This will split the screen and show the rendered markdown you can paste into google docs.
It's pretty quick at this point to just keep paste markdown/copy result/repeat as long as you don't have hundreds of docs.
Of course, if it's a ton of docs, you'll want something more automated than this.
One variation of the suggestion to use pandoc: try using the docx format instead of odt. Google Docs handles MS Office files natively so I found formatting was preserved somewhat better using this approach.
Revised steps:
Convert markdown to DOCX using pandoc: pandoc MyFile.md -f markdown -t docx -s -o MyFile.docx
Upload MyFile.docx into your Google Drive folder
Double-click MyFile.docx in the web version of Drive
Google Drive will open MyFile.docx in a new tab
I don't know of a tool or library that allows for a direct conversion from markdown to a google doc.
Maybe you can convert your markdown to an intermediary format compatible with Google Docs (viable formats include .docx, .docm .dot, .dotx, .dotm, .html, plain text (.txt), .rtf and .odt) and then go from there.
You just need to find a tool that can convert markdown to one of those formats and also process your files in bulk (maybe some command-line utility could help with that).
There is the Google Docs Addon Markdown to Docs ... which converts Markdown to Google Docs.
It has its limitations due to the Gdoc format but works otherwise very well.
#!/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
Related
Is there a way to save a leaflet-shiny script as a single executable HTML file? For example for a leaflet script you can use:
saveWidget(map, file = "mymap.html")
Then the html file will contain all the script and infromation that can be opened in a web browser and the script will run as in Rstudio.
This does not seem to work once shiny was integrated.
I don't think you can do that.
Below are listed the available options to deploy a Shiny App
https://shiny.rstudio.com/deploy/
The following also looks promising for what you are looking to do
Share as R scripts (assumes R Studio is installed)
https://shiny.rstudio.com/tutorial/written-tutorial/lesson7/
I'm trying to convert a html file (or preformatted html String) to Google Docs using drive api v3 and android studio, using these lines:
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle("report.html")
.setMimeType("text/html")
.build();
(I extract the code from android-demos-master examples )
If I try put another mimetype like "application/vnd.google-apps.document", my app crash. I want to upload the file and convert to Gdocs editor or Docx. I need convert before or after upload the file. Can someone guide me?
Using the python libraries, I found I had to specify two mimetypes:
Use 'application/vnd.google-apps.document' when creating the metadata for the Drive file. This is the type of file you want created - a Google Document.
Use 'text/html' for the object representing uploaded data, as that is the type of the content. In python, this were objects of type io.MediaUpload (file upload) or io.MediaIoBaseUpload (in-memory content).
I imagine it's something similar in Java.
I'm following the HTTrack docs example here: http://httrack.kauler.com/help/User-defined_structure
The site I need to scrape has URLs in this structure:
https://www.example.com/index.php?HelpTopics
https://www.example.com/index.php?MoreHelp
etc.
With HTTrack, I want to download the site save the files in the format
HelpTopics.html MoreHelp.html etc.
I'm using this on the command line modified from the docs linked above:
httrack "https://www.example.com" %n%[index.php?:-:::].%t
but I still get all files saved as index2b26.html and index2de7.html etc.
What am I doing wrong with the HTTrack options? Is this breaking because there are no file extensions on the original site example.com?
I found it's much easier to use wget to save file with their original names. This does it:
wget --mirror -p --convert-links --content-disposition --trust-server-names -P examplefolder http://www.example.com
From the link, the param in %[param:before:after:empty:notfound] is supposed to be a variable in a GET query. Since your URL does not have a variable, I think the default filename would've been right.
I'm using the last version of PHPStorm, which is 7 I think and want to have file support for files using a pattern such as *.extension but those don't have an extension. I tried pattern *, which works, but puts all of my files in bash highlighting.
Does anyone have a solution for that without using the .sh extension?
Edit:
Bash file are recognize with extension .sh and .bash. It's working nicely, but what I want is to set default file type on files with no extension. If I add .* or * in the list of bash file, all my files are recognize like bash file.
Hope it's more clear, sorry for the probable mistake in my English.
It may seem weird - but you can try to actually list the files you're using explicitly reading their names.
Not sure of your use-case, but I needed it for git hooks, and there's not so much names for existing git hooks, so it's not that hard to list those :)
For the reference:
Preferences > Editor > File Types > Bourne Again Shell:
I'm trying to find a way to automatically download all links from a web page, but I also want to rename them. for example:
<a href = fileName.txt> Name I want to have </a>
I want to be able to get a file named 'Name I want to have' (I don't worry about the extension).
I am aware that I could get the page source, then parse all the links, and download them all manually, but I'm wondering if there are any built-in tools for that.
lynx --dump | grep http:// | cut -d ' ' -f 4
will print all the links that can be batch fetched with wget - but is there a way to rename the links on the fly?
I doubt anything does this out of the box. I suggest you write a script in Python or similar to download the page, and load the source (try the Beautiful Soup library for tolerant parsing). Then it's a simple matter of traversing the source to capture the links with their attributes and text, and download the files with the names you want. With the exception of Beautiful Soup (if you need to be able to parse sloppy HTML), all you need is built in with Python.
I solved the problem by converting the web page entirely to unicode on the first pass (using notepad++'s built-in conversion)
Then I wrote a small shell script that used cat, awk and wget to fetch all the data.
Unfortunately, I couldn't automate the process since I didn't find any tools for linux which would convert an entire page from KOI8-R to unicode.