Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

2 votes
2 answers
737 views
Converting html anchors to markdown using sed regex
I've been slowly converting a blog of mine to markdown. The final thing to do is replacing all the html anchors with markdown. I've come up this sed regex, which for all intents and purposes should do what I want, but it doesn't. Source data: $ cat /tmp/test on reddit or Lifehacker Sed command: $ se...
I've been slowly converting a blog of mine to markdown. The final thing to do is replacing all the html anchors with markdown. I've come up this sed regex, which for all intents and purposes should do what I want, but it doesn't. Source data: $ cat /tmp/test on reddit or Lifehacker Sed command: $ sed -r 's/(.*?)/[\2](\1)/g' /tmp/test on [Lifehacker](https://lifehacker.com/ " target="_blank" rel="noopener) What I want it to return: on [Reddit](https://reddit.com/) or [Lifehacker](https://lifehacker.com/ ")
devilkin (31 rep)
Apr 25, 2020, 09:52 AM • Last activity: Apr 5, 2025, 08:04 PM
23 votes
3 answers
21580 views
convert markdown to pdf in commandline
what is the simplest tool to convert markdown to pdf in commandline? I have found howtos where people suggest to use `pandoc`, but the required packages need gigabytes of dependencies: apt-get install pandoc texlive-latex-base texlive-fonts-recommended texlive-extra-utils texlive-latex-extra is ther...
what is the simplest tool to convert markdown to pdf in commandline? I have found howtos where people suggest to use pandoc, but the required packages need gigabytes of dependencies: apt-get install pandoc texlive-latex-base texlive-fonts-recommended texlive-extra-utils texlive-latex-extra is there some minimal tool that can convert simple markdown to pdf in commandline, that does not require tons of dependencies? I am using Debian 10.
Martin Vegter (586 rep)
Jul 22, 2022, 04:55 AM • Last activity: Mar 16, 2025, 02:02 PM
289 votes
35 answers
325443 views
Markdown Viewer
I found a file formatted with Markdown. Could you suggest what viewer I could use to view this type of file? Hopefully one without a GUI, if it's possible. I am looking for a viewer that could parse markdown file format that does not need any conversion, but something close to that should be okay.
I found a file formatted with Markdown. Could you suggest what viewer I could use to view this type of file? Hopefully one without a GUI, if it's possible. I am looking for a viewer that could parse markdown file format that does not need any conversion, but something close to that should be okay.
Amree (3237 rep)
Nov 17, 2010, 06:52 AM • Last activity: Aug 18, 2024, 02:06 PM
0 votes
1 answers
611 views
curl webpage and convert to markdown
having a dilemma with downloading webpages and converting them to markdown, for example: F=$(curl -O --silent https://www.guru3d.com/story/msi-teases-spatium-m560-ssd-with-innovative-nonmetallic-vc-cooling-technology | pandoc --extract-media="./"${F%.*}"_media" --from html --to markdown_strict -o "$...
having a dilemma with downloading webpages and converting them to markdown, for example: F=$(curl -O --silent https://www.guru3d.com/story/msi-teases-spatium-m560-ssd-with-innovative-nonmetallic-vc-cooling-technology | pandoc --extract-media="./"${F%.*}"_media" --from html --to markdown_strict -o "${F%.*}.md") HTML file downloads fine but the md file that gets created is not given proper name and is of no content. What is wrong in this syntax? Is there maybe some better or easier way of downloading webpages, converting them to markdown and storing html page images locally?
anon
May 31, 2024, 02:12 PM • Last activity: Jun 4, 2024, 03:50 AM
0 votes
1 answers
652 views
Markdown viewer for file list
I'm looking for a command line **Markdown viewer for many .md files** somehow similar to image viewers. I need: * simple/fast navigation: preferably left, right arrows (no combinations like :n, :p), * and a list of .md files as an argument or taken from current dir, * clean output is a plus. It may...
I'm looking for a command line **Markdown viewer for many .md files** somehow similar to image viewers. I need: * simple/fast navigation: preferably left, right arrows (no combinations like :n, :p), * and a list of .md files as an argument or taken from current dir, * clean output is a plus. It may be also achieved by some sophisticated pipe sequence or any customized parameters/shell variables. Anything that works.
sZpak (511 rep)
Nov 17, 2023, 12:13 PM • Last activity: Nov 17, 2023, 11:39 PM
4 votes
3 answers
476 views
How to merge these commands into one?
This is what I am wanting to do: Convert a folder of HTML files into markdown, also copying over the the XML metadata of each of the HTML files by converting into YAML. I have done research and came across the following commands: 1. `find . -name \*.md -type f -exec pandoc -o {}.txt {} \;` * [This w...
This is what I am wanting to do: Convert a folder of HTML files into markdown, also copying over the the XML metadata of each of the HTML files by converting into YAML. I have done research and came across the following commands: 1. find . -name \*.md -type f -exec pandoc -o {}.txt {} \; * [This was found here](https://stackoverflow.com/questions/10323317/batch-processing-pandoc-conversions) , and it is a command that works and uses pandoc, however the file extentions are ".html.md" not ".md" 2. find / -name "*.md" -type f -exec sh -c 'markdown "${0}" > "${0%.md}.html"' {} \; * [This was found here.](https://unix.stackexchange.com/questions/43669/use-find-command-to-convert-markdown-files-to-html) This apparently takes away the ".html.md" and turns into ".md", but it does not use pandoc. 3. pandoc -f html -t markdown -s input.html -o output.md * [This was found here.](https://stackoverflow.com/questions/22866498/use-pandoc-to-create-yaml-metadata-from-html-meta-tags?rq=1) This is the pandoc command that apparently copies over the metadata and turns it into YAML, however it does not work on a folder of files, only on open What I need is to have one single command that uses pandoc, gives the converted files the ".md." extension and not .html.md, and converts the XML metadata into YAML. All of this can be achieved using these three commands, they just need to be merged into one single command.
st john smith (61 rep)
Mar 14, 2015, 03:35 AM • Last activity: Oct 19, 2023, 11:42 AM
1 votes
1 answers
168 views
Changing default editor for markdown bash_profile
I am pretty new to bash/zsh on Mac OX. I am trying to change my `.bash_profile` so that that all markdowns are opened with sublime when I enter `open [filename].md` in terminal. I have created synthetic link to the binary and opening with `subl [filname].md` works just great but when I try to add `e...
I am pretty new to bash/zsh on Mac OX. I am trying to change my .bash_profile so that that all markdowns are opened with sublime when I enter open [filename].md in terminal. I have created synthetic link to the binary and opening with subl [filname].md works just great but when I try to add export EDITOR=subl it does not work so I am assuming I am doing something wrong here. I do not have a .bashrc. Can someone help me?
Sabina Brunswicker (11 rep)
Sep 9, 2023, 04:45 AM • Last activity: Sep 9, 2023, 07:01 PM
12 votes
1 answers
3388 views
Save HTML from clipboard as markdown text
I want to be able to highlight a section of a web page and copy it to the clipboard then save it to my local disk as markdown. I need an efficient way to do that. My current cumbersome method is: 1. highlight section and copy to clipboard 2. open Libre Office Writer 3. paste into Writer 4. save Writ...
I want to be able to highlight a section of a web page and copy it to the clipboard then save it to my local disk as markdown. I need an efficient way to do that. My current cumbersome method is: 1. highlight section and copy to clipboard 2. open Libre Office Writer 3. paste into Writer 4. save Writer doc as HTML 5. open terminal 6. cd to the directory where I saved the HTML 7. pandoc -s -r html /home/me/a/b/mydoc.html -o /home/me/a/b/mydoc.md Obviously, I need a better method! Any suggestions?
MountainX (18888 rep)
Jun 6, 2013, 01:02 AM • Last activity: Apr 17, 2023, 02:36 PM
4 votes
1 answers
1275 views
Extend syntax highlighting for Markdown in Kate?
**Is there a plugin/xml file or any way to extend the capability of Kate to highlight Markdown?** I am really comfortable with Kate (using version 15.12.3) and I use it to write logs. For plain-text readibility I use Markdown, since it is a Markup language that (in my opinion) doesn't need compilati...
**Is there a plugin/xml file or any way to extend the capability of Kate to highlight Markdown?** I am really comfortable with Kate (using version 15.12.3) and I use it to write logs. For plain-text readibility I use Markdown, since it is a Markup language that (in my opinion) doesn't need compilation to look pretty. However, Markdown-syntax-highlighting helps! Luckily, Kate supports some basic syntax highlighting, like highlighting headers (when using #), italic (using * or _), indents, inline code (using backticks) and lists (using - or 1. / 2. / ...). However, some interesting features are missing, e.g. like bold text (using ** or __) highlighting headers in underline style: h1: my header ============= h2: my sub header ----------------- and most importantly for me the syntax highlighting *without indent*, using backticks: a syntax block in markdown can be started with indents (4 spaces): code() but also with 3 backticks:
code()
    highlight.me{}
only in the backtick syntax we can use a notation that some tools convert to language specific highlighting
public class HelloWorld {
       public static void main(String[] args) {
         System.out.println("Hello, World");
       }
    }
Since I use this in plain-text markdown to write code that I can copy and paste without indents, I'd love if Kate would be able to recognize this as code. So are there syntax highlighting extensions for enhanced Markdown support in Markdown?
Honeybear (268 rep)
Oct 9, 2017, 08:55 AM • Last activity: Apr 6, 2023, 12:45 PM
0 votes
2 answers
32 views
Simple filter to unhardwrap multiple paragraphs
I have many markdown files which are hardwrapped to 80 characters. I would like to copy these to paste into textareas (`xclip -sel clipboard < file`), but want them to wordwrap normally. This is simple w/o paragraphs - `tr "\n" " " < file | xclip -sel clipboard`, but turns all text into a run-on par...
I have many markdown files which are hardwrapped to 80 characters. I would like to copy these to paste into textareas (xclip -sel clipboard < file), but want them to wordwrap normally. This is simple w/o paragraphs - tr "\n" " " < file | xclip -sel clipboard, but turns all text into a run-on paragraph which still requires manual copy-editing. Is there a short and simple filter using standard *NIX tools (GNU versions are fine) to delete all "\n" _except_ when there are two next to each other? Ideally something I can remember and retype - less than 30 characters with no files. It feels like something sed should be able to do.
Iiridayn (359 rep)
Feb 13, 2023, 07:52 PM • Last activity: Feb 14, 2023, 12:28 PM
0 votes
1 answers
44 views
Validating flower brace{} liquid tag in markdown validator
WE have a markdown validator that authors use to validate their md files, One check in that is the liquid tag validation where we check for invalid liquid tags in the md files. My requirement is to add a validation to check whether the flower braces are used properly and are properly terminated. eg...
WE have a markdown validator that authors use to validate their md files, One check in that is the liquid tag validation where we check for invalid liquid tags in the md files. My requirement is to add a validation to check whether the flower braces are used properly and are properly terminated. eg if an author opens 5 { , there should be equally 5 closing }. But we also have to exclude code blocks from this validation. any brackets inside a code block should not be validated. code blocks may be a 4 space indentation, 3 backticks or a single backtick.
bracecountopen=$(grep -o -i '{' $file | wc -l);
bracecountclose=$(grep -o -i '}' $file | wc -l);
if [ "$bracecountopen" != "$bracecountclose" ]; then
    throw error
fi
for excluding code blocks
var+=$(grep '^\ \ \ \ [^>]' $file);
while IFS= read -n1 char; do
    if [[ "$char" == "\`" ]]; then
        if [ $flag = 1 ]; then
            flag=0;
            continue
        fi
        flag=1;
    fi
    if [ $flag = 1 ]; then
        # var+=$char;
        echo ""
    fi
done <$file

codebraceopen=$(echo "$var" | grep -o -i '{' | wc -l)
codebraceclose=$(echo "$var" | grep -o -i '}' | wc -l)
let "bracecountopen=bracecountopen - codebraceopen"
let "bracecountclose=bracecountclose - codebraceclose"
Is this approach correct? Is there any better logic to achieve this? The problem here is some author add a tab or 4 spaces before starting their code block with back ticks which makes the content appear twice in the 'var' , it is counted in the 4 space as well as the backticks check. How to fix this?
Anonymous (1 rep)
Dec 15, 2022, 06:48 AM • Last activity: Dec 15, 2022, 10:24 AM
2 votes
3 answers
817 views
Modify URL in markdown link
I'm trying to modify a markdown file. In a file, there are many links like this one. ``` [string one](/stringtwo/#stringthree) ``` I'd like to change these to the following: ``` [string one](stringtwo.html#stringthree) ``` Remove slashes and add `.html`. I tried the following: ``` sed -i 's/](\(\/.*...
I'm trying to modify a markdown file. In a file, there are many links like this one.
[string one](/stringtwo/#stringthree)
I'd like to change these to the following:
[string one](stringtwo.html#stringthree)
Remove slashes and add .html. I tried the following:
sed -i 's/](\(\/.*\)#/](\1.html#/g' file
But it returns [global configuration](/config/.html#globals). It doesn't remove slashes. How can I achieve this using bash or sed?
shin (759 rep)
Nov 18, 2022, 03:48 AM • Last activity: Nov 18, 2022, 05:21 PM
0 votes
1 answers
869 views
How to pretty output of grep for searching within markdown files?
I have a knowledge base (aka Zettelkasten) of markdown files. And I use searching with the next command `grep -irn 'search request' *.md`. All works fine. But I'd like see output with the title of the file and sub header of the found string. The sample ### file.md ```md 1 # Title 2 3 ## Subtitle 4 5...
I have a knowledge base (aka Zettelkasten) of markdown files. And I use searching with the next command grep -irn 'search request' *.md. All works fine. But I'd like see output with the title of the file and sub header of the found string. The sample ### file.md
1 # Title
2
3 ## Subtitle
4
5 yada-yada
### Output
> grep -irn 'yada' *.md

< file.md:5:Title:Subtitle:yada-yada
Can I do this with grep without multiple search in the file? An analogue of [recall](https://www.lesbonscomptes.com/recoll/pages/index-recoll.html) for terminal would be ideal.
kryn (3 rep)
Nov 12, 2022, 04:23 AM • Last activity: Nov 13, 2022, 04:12 AM
0 votes
2 answers
561 views
Extract all links (including multiple links per line) in markdown file
## Sample markdown file: ``` cat index.md # Abstract - To achieve [Work Life Balance](./WorkLifeBalance/WorkLifeBalance.md), first understand what it means and what are the requirements. - Develop right **[Attitude](./Attitude/index.md)** and [Haha](./Haha/Haha.md). - Understand **[attention](./Atte...
## Sample markdown file:
cat index.md

# Abstract

- To achieve [Work Life Balance](./WorkLifeBalance/WorkLifeBalance.md), first understand what it means and what are the requirements.
- Develop right **[Attitude](./Attitude/index.md)** and [Haha](./Haha/Haha.md).
- Understand **[attention](./AttentionManagement/index.md)**, **[time](./TimeManagement/index.md)** and **[task](./TaskManagement/index.md)** management and start implementing those.
## Expected outcome
[Work Life Balance](./WorkLifeBalance/WorkLifeBalance.md)
[Attitude](./Attitude/index.md)
[Haha](./Haha/Haha.md)
[attention](./AttentionManagement/index.md)
[time](./TimeManagement/index.md)
[task](./TaskManagement/index.md)
# Attempts to solve sed -r -n -e 's/.*(\[.*\]\(.*\)).*/\1/p' index.md, but this only mnatches the last link in a line! # Suggestions? I prefer sed, but if its not possible in sed then other tools are also welcome.
Porcupine (2156 rep)
Jul 18, 2022, 03:00 PM • Last activity: Jul 18, 2022, 04:37 PM
4 votes
1 answers
4625 views
Markdown & Pandoc : How to include a specific PDF page as image?
It is currently possible to insert a PDF as an image in markdown files through pandoc by doing this: ```markdown # Hello World ![My PDF file inserted](my-pdf.pdf) ``` Then you convert that markdown file with pandoc: ```bash ~$ pandoc -s -f markdown-implicit_figures my-document.md -o my-document.pdf...
It is currently possible to insert a PDF as an image in markdown files through pandoc by doing this:
# Hello World
![My PDF file inserted](my-pdf.pdf)
Then you convert that markdown file with pandoc:
~$ pandoc -s -f markdown-implicit_figures my-document.md -o my-document.pdf
And it works! **But pandoc only inserts the first page** of my-pdf.pdf. Is it possible to set which page to insert, or better, which pages range? Thanks by advance.
Creasixtine (801 rep)
Apr 5, 2021, 09:04 AM • Last activity: Mar 23, 2022, 01:25 AM
2 votes
1 answers
1804 views
Markdown to PDF Converstion with Pandoc: Make pages a specific size, in inches
So I know you can use `pagesize` and `geometry` to set the page size of the PDFs Pandoc makes to presets (like a5, b5, etc), but is there a way to set a precise pair of dimensions? I'm going to be using the PDF with Amazon Self-Publishing (paperback) and I need the pages to be exactly 5x8in, as that...
So I know you can use pagesize and geometry to set the page size of the PDFs Pandoc makes to presets (like a5, b5, etc), but is there a way to set a precise pair of dimensions? I'm going to be using the PDF with Amazon Self-Publishing (paperback) and I need the pages to be exactly 5x8in, as that's the closest setting KDP has to what I want. Thank you!
Alexis Purslane (663 rep)
Dec 10, 2021, 01:27 AM • Last activity: Dec 10, 2021, 05:28 PM
3 votes
1 answers
3429 views
Customising markdown syntax highlighting in Geany
I'm using Geany 1.23.1 on Lubuntu 13.10. I've copied over `filetypes.markdown` from `/usr/share/geany` to `~/.config/geany/filedefs`. `filetypes.markdown` has the following content: # For complete documentation of this file, please see Geany's main documentation [styling] # Edit these in the colorsc...
I'm using Geany 1.23.1 on Lubuntu 13.10. I've copied over filetypes.markdown from /usr/share/geany to ~/.config/geany/filedefs. filetypes.markdown has the following content: # For complete documentation of this file, please see Geany's main documentation [styling] # Edit these in the colorscheme .conf file instead default=default strong=string_3 emphasis=string_4 header1=keyword_1 header2=keyword_1 header3=keyword_1 header4=keyword_1 header5=keyword_1 header6=keyword_1 ulist_item=tag_unknown olist_item=tag_unknown blockquote=tag_unknown strikeout=tag_unknown hrule=tag_unknown link=keyword_1 code=attribute_unknown codebk=attribute_unknown [settings] # default extension used when saving files extension=mkd # sort tags by appearance symbol_list_sort_mode=1 Why is the third line present: **# Edit these in the colorscheme .conf file instead**? What is wrong with editing filetypes.markdown itself? I would think that, at least from a user's perspective, editing ~/.config/geany/filedefs/filetypes.markdown (or any other filetypes file) would be preferable to editing a .conf file (in ~/.config/geany/colorschemes) as suggested because editing a .conf file would affect all filetypes not just filetype.markdown.
user15760
Oct 30, 2013, 03:44 AM • Last activity: Oct 19, 2021, 06:06 PM
0 votes
1 answers
66 views
Replacig text inside multiple repeating patterns in same line
I have something like this; ``` I like reading **books** and taking **notes** ``` I was trying to get something like this; ``` I like reading books and taking notes ``` Tried doing; ``` sed 's/\*\*\(.*\)\*\*/ \1 /g' a.txt ``` This returns; ``` I like reading books** and taking **notes ``` It wraps a...
I have something like this;
I like reading **books** and taking **notes**
I was trying to get something like this;
I like reading books and taking notes
Tried doing;
sed 's/\*\*\(.*\)\*\*/\1/g' a.txt
This returns;
I like reading books** and taking **notes
It wraps around the whole line. Any way to get around it? *note: I'm using a GNU version of sed*
atheros (256 rep)
Apr 16, 2021, 04:29 PM • Last activity: Apr 16, 2021, 04:54 PM
2 votes
1 answers
1327 views
How to associate markdown files with a web browser?
Out of GUI-based software like ReText or Formiko, and using just a _command-line tool_ like pandoc, is it possible to open markdown files (MIME type association) as an HTML file in a web browser, without any browser-addon too? Notice that the original markdown file may include links to images or any...
Out of GUI-based software like ReText or Formiko, and using just a _command-line tool_ like pandoc, is it possible to open markdown files (MIME type association) as an HTML file in a web browser, without any browser-addon too? Notice that the original markdown file may include links to images or any kind of resources. Therefore, this process should be on-fly (stdout?), without saving the output HTML file to somewhere else like /tmp/ directory. And how can such a command be included in a .desktop file?
Anas R. (161 rep)
Mar 4, 2021, 03:06 PM • Last activity: Mar 21, 2021, 11:19 AM
1 votes
1 answers
193 views
Permissions problem when using ruby based snap 'mdl'
Because I don't understand Ruby, but want to use the ruby based program mdl (markdownlint), I have installed it using snap. While I can run the program, if I try and set up a customizations in a ~/.mdlrc file. I get the following error $ mdl README.md /snap/mdl/171/lib/ruby/gems/2.4.0/gems/mixlib-co...
Because I don't understand Ruby, but want to use the ruby based program mdl (markdownlint), I have installed it using snap. While I can run the program, if I try and set up a customizations in a ~/.mdlrc file. I get the following error $ mdl README.md /snap/mdl/171/lib/ruby/gems/2.4.0/gems/mixlib-config-3.0.6/lib/mixlib/config.rb:63:in `read': Permission denied @ rb_sysopen - /home/mikeg/.mdlrc (Errno::EACCES) from /snap/mdl/171/lib/ruby/gems/2.4.0/gems/mixlib-config-3.0.6/lib/mixlib/config.rb:63:in `from_file' from /snap/mdl/171/lib/ruby/gems/2.4.0/gems/mdl-0.10.0/lib/mdl/cli.rb:122:in `run' from /snap/mdl/171/lib/ruby/gems/2.4.0/gems/mdl-0.10.0/lib/mdl.rb:16:in `run' from /snap/mdl/171/lib/ruby/gems/2.4.0/gems/mdl-0.10.0/bin/mdl:10:in `' from /snap/mdl/171/bin/mdl:23:in `load' from /snap/mdl/171/bin/mdl:23:in `' I don't understand where the permission issue comes from since $ ls -l ~/.mdlrc ~/.mdlrc.style.rb -rw-rw-r-- 1 mikeg mikeg 171 Aug 14 16:06 /home/mikeg/.mdlrc -rw-rw-r-- 1 mikeg mikeg 4 Aug 14 16:06 /home/mikeg/.mdlrc.style.rb and drwxr-xr-x 303 mikeg mikeg 65536 Aug 14 21:53 /home/mikeg As a result, I can't figure out how to fix this. Can anyone help me. Note that I'm running Mate 18.06. SELinux is not installed, but AppArmor is active and going through my /var/log/syslog* files I get
syslog.7.gz:Aug 17 09:08:40 XXXX kernel: [978608.742842] audit: type=1400 audit(1597669720.954:2800): apparmor="DENIED" operation="open" profile="snap.mdl.mdl" name="/home/mi/.mdlrc" pid=13189 comm="ruby" requested_mask="r" denied_mask="r" fsuid=1000 ouid=1000
Thanks, Mike
mikemtnbikes (241 rep)
Aug 14, 2020, 08:36 PM • Last activity: Aug 24, 2020, 01:44 PM
Showing page 1 of 20 total questions