Xah HTML Mode Tutorial

By Xah Lee. Date: . Last updated: .

This page is a tutorial on using Xah HTML Mode

XahTV 2021-09-14 Emacs Xah Html Mode, the Most Powerful Html Editor

Insert Tags

To insert a tag, press Tab (xah-html-insert-tag)

xah html mode insert tag 2021-09-18
xah html mode insert tag

It'll wrap the tag around the current word, line, or block, depending on the tag. Also, if there is selection, it'll wrap around the selection.

To add a class attribute or id attribute, press Ctrl+u Tab. It'll prompt for class name and id. Leave blank if you do not want the attribute.

xah-html-insert-tag is the general way to insert any html tag.

Here's specialized commands to create some commonly used tags:

xah-html-blocks-to-paragraph
Turn blocks into paragraphs. Press Space to repeat.
xah-html-insert-br-tag
insert a br tag.

Create List

xah-html-lines-to-list
Turn lines to a unordered list. Press Ctrl+u first for ordered list.
xah-html-lines-to-def-list
Turn lines to a definition list

Create Table

xah-html-lines-to-table
Turn lines into a table.

Create Link

To create a link, of url, image, pdf, etc, first paste the url or file path, then Alt+x xah-html-any-to-link

xah-html-any-to-link is a smart command, it creates different links for different url/path. For example:

xah-html-any-to-link looks at the input and calls one of the following:

you can call any of these yourself.

Emacs: Insert HTML Tag

Embed Image

To turn a image path into a embedded image with figure and caption, just press Tab (xah-html-any-to-link)

Here's more specific commands:

xah-html-image-path-to-figure-tag
Turn path into img tag with figure and figcaption
xah-html-image-to-img-tag
Turn path into img tag
xah-html-image-to-link
Turn path into a link

Embed Programing Language Source Code

xah-html-insert-pre-tag
Create a pre code with class name of a programing language.
xah-html-pre-code-to-new-file
Move the source code to a temp file. So you can run it.
xah-html-toggle-syntax-color-tags
add or remove span tags that colors the source code.
xah-html-dehtmlize-pre-code-buffer
remove all span markup in buffer that colors the source code.
xah-html-redo-syntax-coloring-buffer
Redo all pre source code blocks in buffer.

Tag Navigation

xah-html-prev-begin-tag
Goto previous begin tag. Press to repeat.
xah-html-next-begin-tag
Goto next begin tag. Press to repeat.
xah-html-goto-matching-tag
Goto element's begin/end tag. Press Space to repeat.

Select Element

xah-html-select-current-element
Select the current element. Press Space to repeat.

Remove Tags

xah-html-delete-tag-pair
Delete the open and close tag pair. (before cursor) Press Space to repeat. Useful info in tag's attribute, such as link url, image source path, are preserved in a markdown format. Not useful innerText such as JavaScript code in script tag, are removed with the tags.
xah-html-remove-list-tags
Delete all list tags. (of current block.)
xah-html-remove-paragraph-tags
Delete all p tags. (of current block.)
xah-html-remove-html-tags
Delete all tags. (of current block.)
xah-html-html-to-text
Delete tags but preserve info. (of current block.) For example, url in link remain, image path remain. This command basically convert html to plain text in best format as much as possible.
xah-html-join-tags
Join two same elements together. Cursor must be in between the end tag and begin tag. Press Space to repeat.

preview in a browser

xah-html-open-in-browser
Open buffer in default browser.
xah-html-open-in-chrome
In Chrome. If cursor is on a url, open the url, else buffer.
xah-html-open-in-safari
In Safari. If cursor is on a url, open the url, else buffer.
xah-html-open-in-firefox
In Firefox. If cursor is on a url, open the url, else buffer.
xah-html-open-in-brave
In Brave. If cursor is on a url, open the url, else buffer.

Abbreviation

Type hr will become <hr />

Alt+x list-abbrevs to see all abbrevs.

Insert HTML Template

Type htmlt to insert a whole html template.

view the image in a image tag

Just move cursor to the file path, press Enter to open it.

open the current directory in OS desktop

Emacs: Open File in External App

History of Xah Html Mode

Xah Html Mode began in 2013. And went thru a complete rewrite in 2021-08. There are a lot to code. If you like it, please pay me.

HTML

If you have a question, put $5 at patreon and message me on xah discord.
Or support me by Buy Xah Emacs Tutorial