Skip to content

Repository for htmx extensions such as asciidoctor rendering

License

Notifications You must be signed in to change notification settings

mariotoffia/htmx-extensions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

htmx-extensions

htmx-asciidoc

This extension allows you to include AsciiDoc files in your HTML using htmx.

Tip
💡 Run the example by cd examples/asciidoc; go run main.go and open http://localhost:8080 in your browser to test it out.

It will make it possible to include AsciiDoc content in your HTML using the hx-ext="asciidoc" attribute.

<body hx-ext="asciidoc">
    <button
            hx-get="/readme"
            hx-target="#content"
            asciidoc-attributes="showtitle=true,sectnums=true">
        Load AsciiDoc
    </button>
    <div id="content"></div>
</body>

When the server returns a content type of text/asciidoc, the extension will render the AsciiDoc content in the target element.

It is possible to disable the rendering of text/asciidoc content by adding the asciidoc-disable attribute to the element. Then the extension will pass-through the content to the target element un-rendered.

In order to use it, make sure that you’ve loaded asciidoctor.js and htmx-asciidoc.js in your HTML.

<head>
    <link href="https://cdn.jsdelivr.net/npm/@asciidoctor/[email protected]/dist/css/asciidoctor.min.css" rel="stylesheet"> // (1)
    <script src="https://cdn.jsdelivr.net/npm/@asciidoctor/[email protected]/dist/browser/asciidoctor.min.js"></script>
    <script src="https://unpkg.com/[email protected]/dist/htmx.min.js"></script> // (2)
    <script src="https://cdn.jsdelivr.net/gh/mariotoffia/[email protected]/asciidoc/htmx-asciidoc.js"></script> // (3)
</head>
  1. Add some default asciidoc styles.

  2. Since it is a HTMX extension, load it after HTMX itself.

  3. Make sure to load this last so it will have access to the asciidoctor object.

Note
You need to serve the asciidoctor.js file from your server (in this setup).

If you have styles that will be affected by the asciidoc styles, you can include them using asciidoc-stylesheet attribute. It will then inline the styles by scoping them to the target element.

Custom Asciidoctor Binding

You may publish the Asciidoctor instance on the window object, the htmx-asciidoc extension will pick this up first. Then it will try to find the 3.x style asciidoc module, lastly the 2.x style global Asciidoctor object.

About

Repository for htmx extensions such as asciidoctor rendering

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published