Skip to content

Instantly share code, notes, and snippets.

@mmynsted
Created May 12, 2022 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmynsted/4478021ce828979c8a4d016dd6dff609 to your computer and use it in GitHub Desktop.
Save mmynsted/4478021ce828979c8a4d016dd6dff609 to your computer and use it in GitHub Desktop.

Example simple markdown tag

When I copy the following to the pasteboard.

![one-time-share-2](assets/one-time-share-2.png)

The AST looks like this.

$ pbpaste |pandoc -f markdown -t native
[ Para
    [ Image
        ( "" , [] , [] )
        [ Str "one-time-share-2" ]
        ( "assets/one-time-share-2.png" , "fig:" )
    ]
]

To HTML this looks like this.

$ pbpaste |pandoc -f markdown -t html
<figure>
<img src="assets/one-time-share-2.png" alt="one-time-share-2" />
<figcaption aria-hidden="true">one-time-share-2</figcaption>
</figure>

If I change the HTML to include the width it looks like this.

<figure>
<img src="assets/one-time-share-2.png" alt="one-time-share-2" width="80%" />
<figcaption aria-hidden="true">one-time-share-2</figcaption>
</figure>

The native for that looks like the following.

$ pbpaste |pandoc -f html -t native
[ Para
    [ Image
        ( "" , [] , [ ( "width" , "80%" ) ] )
        [ Str "one-time-share-2" ]
        ( "assets/one-time-share-2.png" , "fig:" )
    ]
]

If I then convert that back to markown it looks like this.

$ pbpaste |pandoc -f native -t markdown
![one-time-share-2](assets/one-time-share-2.png){width="80%"}

It is not lost on me that I could simply append {width="80"} to the end of the markdown image tags (that are programatically generated). Then pass that through pandoc to get the HTML.

So using the markdown from just above, the output would be what I want.

$ pbpaste |pandoc -f markdown -t html
<figure>
<img src="assets/one-time-share-2.png" style="width:80.0%"
alt="one-time-share-2" />
<figcaption aria-hidden="true">one-time-share-2</figcaption>
</figure>

The problem is that it is not a standalone app or a fitler, I would have to use something to transform the original markdown formatted image tag to the one with the {width="80%"} appended. This work needs to be performed somewhere, and a standalone app or filter seems like the right answer.

Any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment