Xah Talk Show 2025-11-23 Ep716 Emacs Lisp Call Python Markdown to HTML

xah talk show ep716 13ff0
xah talk show ep716 13ff0

Video Summary (Generated by AI, Edited by Human.)

  • Intro. write an Elisp command in Emacs that calls an external Python program to convert Markdown text to HTML (6:01).
  • Ask grok AI for a Python Markdown Converter. (9:52).
  • Test the Python Program. (35:13, 36:17).
  • Begin writing the Emacs Lisp Command.
  • Identify the Markdown text. (either a selected region or a text block separated by blank lines) (41:49).
  • Call the Python script. (34:26, 1:09:06).
  • Take input from STDIN. (1:05:38).
  • Run Python Script from PowerShell. (1:11:44).
  • Integrating with Emacs Lisp. (1:20:16).
  • Demo success. (1:33:19)
  • Find Python Library Location. (1:38:35).
  • Emacs. do you kill buffer you don't use anymore. (17:27)
  • Problem of Emacs mark-paragraph (48:59)

links

how to write python markdown to html

pip install markdown
xah talk show ep716 387f5
xah talk show ep716 387f5
import markdown

xmarkdown_text = """
# Hello World

This is **bold** and this is *italic*.

- Item 1
- Item 2
- Item 3

"""

xhtml = markdown.markdown(xmarkdown_text)

print(xhtml)

get and pass stdin

# 2025-11-23

import markdown
import sys

xmarkdown_text = sys.stdin.read()

xhtml = markdown.markdown(xmarkdown_text)

print(xhtml)
# pass stdin to the python script

Get-Content -Path "~/web/xahlee_info/talk_show/xx_sample_markdown.md" | python markdown_to_html.py -
xah talk show ep716 stdin 38cae
xah talk show ep716 stdin 38cae

emacs lisp call python xah-html-markdown-to-html-python

;; -*- coding: utf-8; lexical-binding: t; -*-

(defun xah-html-markdown-to-html-python ()
  "Convert the current text block or selection of markdown to HTML.
Require python and python markdown library installed.
(pip install markdown)

Created: 2025-11-23
Version: 2025-11-24"
  (interactive)
  (let (xbeg xend (xcode "import markdown
import sys
print(markdown.markdown(sys.stdin.read()))"))
    (seq-setq (xbeg xend) (if (region-active-p) (list (region-beginning) (region-end)) (list (save-excursion (if (re-search-backward "\n[ \t]*\n" nil 1) (match-end 0) (point))) (save-excursion (if (re-search-forward "\n[ \t]*\n" nil 1) (match-beginning 0) (point))))))
    (shell-command-on-region xbeg xend (format "python -c \"%s\"" xcode) nil t nil t)))

Emacs. do you kill buffer you don't use

emacs. why not use mark-paragraph

emacs mark-paragraph 2025-11-25 22d86
emacs mark-paragraph 2025-11-25 22d86

markdown to HTML