Last active
February 1, 2023 19:06
-
-
Save xapax/1c150ac42fc48f09a67c68e4841ed364 to your computer and use it in GitHub Desktop.
Converting html to markdown - useful when migrating from wordpress to jekyll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| filename=$(basename "$1") | |
| dirname=$(dirname "$1") | |
| extension="${filename##*.}" | |
| filename_without_extension="${filename%.*}" | |
| sed -i -e 's/<p>//g' $1 | |
| sed -i -e 's/<\/p>/\n/g' $1 | |
| sed -i -e 's/<h1>/# /g' $1 | |
| sed -i -e 's/<\/h1>//g' $1 | |
| sed -i -e 's/<h2>/## /g' $1 | |
| sed -i -e 's/<\/h2>//g' $1 | |
| sed -i -e 's/<h3>/### /g' $1 | |
| sed -i -e 's/<\/h3>//g' $1 | |
| sed -i -e 's/<h4>/#### /g' $1 | |
| sed -i -e 's/<\/h4>//g' $1 | |
| sed -i -e 's/<strong>/**/g' $1 | |
| sed -i -e 's/<\/strong>/**/g' $1 | |
| sed -i -e 's/<br \/>//g' $1 | |
| sed -i -e 's/<ul>//g' $1 | |
| sed -i -e 's/<\/ul>//g' $1 | |
| sed -i -e 's/<ol>//g' $1 | |
| sed -i -e 's/<\/ol>//g' $1 | |
| sed -i -e 's/<li>/- /g' $1 | |
| sed -i -e 's/<\/li>//g' $1 | |
| sed -i -e 's/<pre>/```\n/g' $1 | |
| sed -i -e 's/<\/pre>/```\n/g' $1 | |
| sed -i -e 's/<a href="/[](/g' $1 | |
| sed -i -e 's/<\/a>//g' $1 | |
| sed -i -e 's/&/\&/g' $1 | |
| sed -i -e 's/"/"/g' $1 | |
| sed -i -e 's/>/>/g' $1 | |
| sed -i -e 's/</</g' $1 | |
| sed -i -e 's/ //g' $1 | |
| sed -i -e 's/\[code\]/```/g' $1 | |
| sed -i -e 's/\[\/code\]/```/g' $1 | |
| sed -i -e 's/\[code lang="javascript"\]/```javascript/g' $1 | |
| sed -i -e 's/\[code lang="bash"\]/```bash/g' $1 | |
| sed -i -e 's/\[code lang="php"\]/```php/g' $1 | |
| sed -i -e 's/\[code lang="python"\]/```python/g' $1 | |
| sed -i -e 's/\[code lang="html"\]/```html/g' $1 | |
| sed -i -e 's/\[code lang="js"\]/```javascript/g' $1 | |
| sed -i -e 's/\[code lang="c"\]/```c/g' $1 | |
| sed -i -e 's/\[code lang="jade"\]/```jade/g' $1 | |
| sed -i -e 's/\[code lang="css"\]/```css/g' $1 | |
| sed -i -e 's/\[code language="html"\]/```html/g' $1 | |
| sed -i -e 's/\[code language="js"\]/```javascript/g' $1 | |
| sed -i -e 's/\[code language="php"\]/```php/g' $1 | |
| sed -i -e 's/\[code language="css"\]/```css/g' $1 | |
| sed -i -e 's/\[code language="bash"\]/```bash/g' $1 | |
| sed -i -e 's/<code>/```/g' $1 | |
| sed -i -e 's/<\/code>/```/g' $1 | |
| sed -i -e 's/email@gmail.com/tomeail@protonmail.com/g' $1 | |
| mv $1 $dirname/$filename_without_extension.md |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment