Advertisement
smeech

Espanso trigger to accompany ConvertMarkdown.ps1

Dec 7th, 2024 (edited)
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 1.17 KB | None | 0 0
  1. ## Espanso trigger to accompany ConvertMarkdown.ps1
  2. ## https://pastebin.com/cj4NAK90
  3.  
  4.   - trigger: :conv
  5.     replace: '{{output}}'
  6.     vars:
  7.       - name: clipb
  8.         type: clipboard
  9.       - name: output
  10.         type: script
  11.         params:
  12.           args:
  13.             - pwsh
  14.             - /home/stephen/.config/espanso/scripts/ConvertMarkdown.ps1
  15.             - -markdownText
  16.             - "{{clipb}}"
  17.  
  18.  
  19. ## Neater inline solution using Python libraries instead,
  20. ## to convert Markdown→HTML→Plain text:
  21.  
  22.   - trigger: :conv
  23.     replace: '{{output}}'
  24.     vars:
  25.       - name: clipb
  26.         type: clipboard
  27.       - name: output
  28.         type: script
  29.         params:
  30.           args:
  31.            - python
  32.             - -c
  33.             - |
  34.              from bs4 import BeautifulSoup
  35.               from markdown import markdown
  36.               import re
  37.               args = """{{clipb}}"""
  38.               html = markdown(args)
  39.               html = re.sub(r'<pre>(.*?)</pre>', ' ', html)
  40.               html = re.sub(r'<code>(.*?)</code>', ' ', html)
  41.               text = ''.join(BeautifulSoup(html, "html.parser").findAll(text=True))
  42.               print(text)
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement