# How can I set render-image.html to handle both md and html syntax of image insetion

**URL:** https://discourse.gohugo.io/t/how-can-i-set-render-image-html-to-handle-both-md-and-html-syntax-of-image-insetion/44711
**Category:** support
**Created:** [June 5, 2023, 5:23pm UTC](https://discourse.gohugo.io/t/how-can-i-set-render-image-html-to-handle-both-md-and-html-syntax-of-image-insetion/44711 "2023-06-05T17:23:03Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Reed-yang](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/reed-yang/32/19608_2.png) [@Reed-yang](https://discourse.gohugo.io/u/Reed-yang)
#### Post date: [June 5, 2023, 5:23pm UTC](https://discourse.gohugo.io/t/how-can-i-set-render-image-html-to-handle-both-md-and-html-syntax-of-image-insetion/44711/1 "2023-06-05T17:23:03Z")

</div>

I’m new to HUGO, and have always been writing .md in Typora.

Typora is a great editor but it has a strange built-in image zoom design: when I do not zoom the pic, the image insert style is typically markdown like this `![image-xx](http://img.xx.xx/image-xx.png)`

But when I sometimes want to zoom, the Typora auto change the syntax like: `<img src="http://img.xx.xx/image-xx.png" alt="image-xx" style="zoom: 67%;" />`

Now the qusetion is, I don’t kown much of Go or html, How can I write the **render-image.html** templete to handle these two syntax in a single .md file

I’ve try ChatGPT, response like this

```html
{{- if eq .OutputFormat.Name "html" -}}
  {{- if eq .Page.Extension ".md" -}}
    {{- $figureRegex := `!\[([^\]]+)]\(([^)]+)\s*("(?:[^"]*)"|'(?:[^']*)'|)(?:\s*([^)]*))?\)` -}}
    {{- $matches := findREAll $figureRegex .Content -}}
    {{- range $i, $e := $matches -}}
      {{- $alt := index $e 1 -}}
      {{- $src := index $e 2 | safeURL -}}
      {{- $title := index $e 4 -}}
      <figure>
        <img src="{{ $src }}" alt="{{ $alt }}"{{ with $title }} title="{{ $title }}"{{ end }}>
        {{ with $title }}<figcaption>{{ . }}</figcaption>{{ end }}
      </figure>
    {{- end -}}
  {{- else -}}
    {{- $src := .Destination | absURL -}}
    {{- $alt := .Params.alt | default "" -}}
    {{- $title := .Params.title -}}
    <figure>
      <img src="{{ $src }}" alt="{{ $alt }}"{{ with $title }} title="{{ $title }}"{{ end }}>
      {{ with $title }}<figcaption>{{ . }}</figcaption>{{ end }}
    </figure>
  {{- end -}}
{{- end -}}

```

Use regex is a nice try, but this code brings so many syntax errors, and I can not solve them well 0.0

---

<div class="post-metadata">

### Author: ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)
#### Post date: [June 5, 2023, 7:51pm UTC](https://discourse.gohugo.io/t/how-can-i-set-render-image-html-to-handle-both-md-and-html-syntax-of-image-insetion/44711/2 "2023-06-05T19:51:45Z")

</div>

There are so many things wrong with the code above that I don’t even know where to begin.

If you want to leverage Hugo’s image render hook, don’t zoom in Typora.

Also, the CSS `zoom` property is still considered non-standard.

---

<div class="post-metadata">

### Author: ![Reed-yang](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/reed-yang/32/19608_2.png) [@Reed-yang](https://discourse.gohugo.io/u/Reed-yang)
#### Post date: [June 6, 2023, 2:52am UTC](https://discourse.gohugo.io/t/how-can-i-set-render-image-html-to-handle-both-md-and-html-syntax-of-image-insetion/44711/3 "2023-06-06T02:52:03Z")

</div>

Now I wonder How render-image works, is my thought about tackle these two syntax here even doable?Why the generates of static html just ignore the `<img src="http://img.xx.xx/image-xx.png" alt="image-xx" style="zoom: 67%;" />` insertion code

---

<div class="post-metadata">

### Author: ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)
#### Post date: [June 6, 2023, 3:57am UTC](https://discourse.gohugo.io/t/how-can-i-set-render-image-html-to-handle-both-md-and-html-syntax-of-image-insetion/44711/4 "2023-06-06T03:57:44Z")

</div>

> [@Reed-yang](#):
>
> Why the generates of static html just ignore the `<img src="http://img.xx.xx/image-xx.png" alt="image-xx" style="zoom: 67%;" />` insertion code

I’m not sure I understand your question. View source in your browser (typically `Ctrl+U`). Do you see:

```auto
<!-- raw HTML omitted -->

```

If yes, change your site configuration:

```plaintext
[markup.goldmark.renderer]
unsafe = true

```

It is safe if _you_ control the content.

---

<div class="post-metadata">

### Author: ![Reed-yang](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/reed-yang/32/19608_2.png) [@Reed-yang](https://discourse.gohugo.io/u/Reed-yang)
#### Post date: [June 6, 2023, 9:00am UTC](https://discourse.gohugo.io/t/how-can-i-set-render-image-html-to-handle-both-md-and-html-syntax-of-image-insetion/44711/5 "2023-06-06T09:00:12Z")

</div>

THX for reply! Your answer solved it perfectly！

---

<div class="post-metadata">

### Author: ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)
#### Post date: [June 8, 2023, 9:00am UTC](https://discourse.gohugo.io/t/how-can-i-set-render-image-html-to-handle-both-md-and-html-syntax-of-image-insetion/44711/6 "2023-06-08T09:00:14Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
