Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Espanso trigger to accompany ConvertMarkdown.ps1
- ## https://pastebin.com/cj4NAK90
- - trigger: :conv
- replace: '{{output}}'
- vars:
- - name: clipb
- type: clipboard
- - name: output
- type: script
- params:
- args:
- - pwsh
- - /home/stephen/.config/espanso/scripts/ConvertMarkdown.ps1
- - -markdownText
- - "{{clipb}}"
- ## Neater inline solution using Python libraries instead,
- ## to convert Markdown→HTML→Plain text:
- - trigger: :conv
- replace: '{{output}}'
- vars:
- - name: clipb
- type: clipboard
- - name: output
- type: script
- params:
- args:
- - python
- - -c
- - |
- from bs4 import BeautifulSoup
- from markdown import markdown
- import re
- args = """{{clipb}}"""
- html = markdown(args)
- html = re.sub(r'<pre>(.*?)</pre>', ' ', html)
- html = re.sub(r'<code>(.*?)</code>', ' ', html)
- text = ''.join(BeautifulSoup(html, "html.parser").findAll(text=True))
- print(text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement