Skip to content

Instantly share code, notes, and snippets.

@anonymous1184
Last active December 28, 2023 12:08
Show Gist options
  • Save anonymous1184/33b2511412158f286d8a719da4f38790 to your computer and use it in GitHub Desktop.
Save anonymous1184/33b2511412158f286d8a719da4f38790 to your computer and use it in GitHub Desktop.

First and most important my friend: don't get frustrated, RegEx is an entity on its own and complex enough to justify head scratching.

Let's split your issue into pieces:

  • The HTML.
  • The expression.
  • The replacement.
  • How to loop.

The HTML

You are trying to match any img tag, the tag is an inline element (meaning that it doesn't have other tags in between), it also is in the XHTML form (<tag />, which is not recommended BTW).

The upside is that is generated, and the generator did a pretty good job at being uniform, always the same template, even the double space between the source and the width attributes.

<img src="SRC"  width="WIDTH" alt="ALT" title="TITLE" />

The expression

The HTML spec is very clear on how attributes for tags should be delimited: always in the same line and (optionally) enclosed in quotes. I have almost never encounter HTML tags with attributes without quotes, so the delimiter are the quotes.

In other words, you'll be matching every character up to the quotes, if you wanted to grab each of the attributes in a named group:

<img src="(?<SRC>[^"]+)"  width="(?<WIDTH>[^"]*)" alt="(?<ALT>[^"]*)" title="(?<TITLE>[^"]*)" \/>

Please note the difference between src and the others, src has a + while the other use *; that denotes a required attribute and the optional ones.

Here is the regex101 for that particular example.

Glad you use regex101, gives a lot of perspective on how an expression will work.

The replacement

This one is the most straightforward, as is just swiping one thing with the other.

This particular regex is heavy on the quotes and as you know in AHK a quote is escaped with another quote. That is in the expression syntax, while a literal assignment doesn't need it.

I'm a fierce advocate of the expression syntax, but in cases like this, one could argue makes sense:

; Literal
regex = <img src="(?<SRC>[^"]+)"  width="(?<WIDTH>[^"]*)" alt="(?<ALT>[^"]*)" title="(?<TITLE>[^"]*)" \/>

; Expression
regex := "<img src=""(?<SRC>[^""]+)""  width=""(?<WIDTH>[^""]*)"" alt=""(?<ALT>[^""]*)"" title=""(?<TITLE>[^""]*)"" \/>"

It is up to you which one to chose, as literal assignment can make a quick test/edit in regex101.

txt =
    (LTrim %
    Hello
    <img src="001%20assets/AsexualPrideFlag.png"  width="100" alt="The Asexual Flag" title="The Asexual Flag" />
    World
    )
regex = <img src="(?<SRC>[^"]+)"  width="(?<WIDTH>[^"]*)" alt="(?<ALT>[^"]*)" title="(?<TITLE>[^"]*)" \/>
RegExMatch(txt, "iO)" regex, match)
align := ""
alt := match.alt
src := match.src
title := match.title
width := match.width
tpl =
    (LTrim
    {r, out.width='%width%', out.extra='', fig.align='%align%', fig.cap='%alt%', fig.title ='%title%'}
    knitr::include_graphics("%src%")
    )
OutputDebug % txt
OutputDebug -----
txt := StrReplace(txt, match[0], tpl)
OutputDebug % txt

The above will output the desired result:

Hello
<img src="001%20assets/AsexualPrideFlag.png"  width="100" alt="The Asexual Flag" title="The Asexual Flag" />
World
-----
Hello
{r, out.width='100', out.extra='', fig.align='', fig.cap='The Asexual Flag', fig.title ='The Asexual Flag'}
knitr::include_graphics("001%20assets/AsexualPrideFlag.png")
World

Please note that the template in the OP has a placeholder for %align% but I have no idea what to put there, so I left it blank.

How to loop

AutoHotkey unlike other PCRE implementations doesn't have a "match all" mode that captures all the matches in a single go, you need to iterate over the original text keeping track of the position where you start looking for the next match (to avoid infinite loops).

For performance reasons, you should always keep track of the position, but for some replacements is not actually needed. The logic behind this is that if the replacement modifies the original text to the extent the match is not found again, you can opt out the whole position tracking.

However, if you have several hundred thousand replacements, you really need to track where to start to avoid overhead. In this case, is small enough to get away with it, but let's see first how to do it while tracking it and then we'll simplify.

Let's get to how the loop works:

RegExMatch() returns the position where the match was found, so a while will loop until it find no matches:

while (RegExMatch(...)) {
    ; do stuff
}

If you were not to modify the contents of the original text it will get stuck looping, because it will always return the first match, that is (aside from performance) why it is recommended to keep track of the position.

This is the complete function call:

foundPosition := RegExMatch(haystack, RegExNeedle, outputVariable, startingPosition)

And the loop changes its form:

p := 1
while (p := RegExMatch(txt, regex, match, p)) {
    ; do stuff
}

p := 1 is to declare the initial position where to start, virtually:

; Initial position -----------------------↓
while (p := RegExMatch(txt, regex, match, 1))

In the first iteration, the RegExMatch() will start at the beginning and returns the position where it finds the match (say 7), so by the second iteration you would be:

; Initial position -----------------------↓
while (p := RegExMatch(txt, regex, match, 7))

That's how the position is tracked, you feed as an input argument the p variable and the returned position is assigned to the same variable when the function returns.

Now when inside the loop you are going to change the structure of the text, so you need to adjust the value of p accordingly.

You are going to change an HTML tag into two lines (making the text grow), so you need to include that character count into the starting position for the next match. The same would apply if instead you shrink the text, you need to set p to the position where to start looking up again.

Given the text:

    **1** <img src="001%20assets/AsexualPrideFlag.png"  width="100" alt="The Asexual Flag" title="The Asexual Flag" />
    **2** <img src="001%20assets/AsexualPrideFlag.png"  width="100" alt="" title="" />

The first loop will have p := 1, do the replacement and convert the text into:

**1** {r, out.width='100', out.extra='', fig.align='', fig.cap='The Asexual Flag', fig.title ='The Asexual Flag'}
knitr::include_graphics("001%20assets/AsexualPrideFlag.png")
**2** <img src="001%20assets/AsexualPrideFlag.png"  width="100" alt="" title="" />

RegExMatch() will return 7 where it finds the first tag, then you will replace the tag with the 2 lines of text, now you need to add p + lengthOfTheReplacement, making p := 175; which is the position next to the end of the replacement (the first asterisk for **2**).

Putting all together:

txt =
    (LTrim %
    **1** <img src="001%20assets/AsexualPrideFlag.png"  width="100" alt="The Asexual Flag" title="The Asexual Flag" />
    **2** <img src="001%20assets/AsexualPrideFlag.png"  width="100" alt="" title="" />
    3 <img src="001%20assets/AsexualPrideFlag.svg"  width="100" alt="The Asexual Flag" title="The Asexual Flag" />
    4 <img src="001%20assets/AsexualPrideFlag.svg"  width="100" alt="The Asexual Flag" title="The Asexual Flag" />
    )
OutputDebug % txt
OutputDebug -----
p := 1
regex = <img src="(?<SRC>[^"]+)"  width="(?<WIDTH>[^"]*)" alt="(?<ALT>[^"]*)" title="(?<TITLE>[^"]*)" \/>
while (p := RegExMatch(txt, "iO)" regex, match, p)) {
    align := ""
    alt := match.alt
    src := match.src
    title := match.title
    width := match.width
    tpl =
        (LTrim
        {r, out.width='%width%', out.extra='', fig.align='%align%', fig.cap='%alt%', fig.title ='%title%'}
        knitr::include_graphics("%src%")
        )
    txt := StrReplace(txt, match[0], tpl)
    p += StrLen(tpl)
}
OutputDebug % txt

The results:

**1** <img src="001%20assets/AsexualPrideFlag.png"  width="100" alt="The Asexual Flag" title="The Asexual Flag" />
**2** <img src="001%20assets/AsexualPrideFlag.png"  width="100" alt="" title="" />
3 <img src="001%20assets/AsexualPrideFlag.svg"  width="100" alt="The Asexual Flag" title="The Asexual Flag" />
4 <img src="001%20assets/AsexualPrideFlag.svg"  width="100" alt="The Asexual Flag" title="The Asexual Flag" />
-----
**1** {r, out.width='100', out.extra='', fig.align='', fig.cap='The Asexual Flag', fig.title ='The Asexual Flag'}
knitr::include_graphics("001%20assets/AsexualPrideFlag.png")
**2** {r, out.width='100', out.extra='', fig.align='', fig.cap='', fig.title =''}
knitr::include_graphics("001%20assets/AsexualPrideFlag.png")
3 {r, out.width='100', out.extra='', fig.align='', fig.cap='The Asexual Flag', fig.title ='The Asexual Flag'}
knitr::include_graphics("001%20assets/AsexualPrideFlag.svg")
4 {r, out.width='100', out.extra='', fig.align='', fig.cap='The Asexual Flag', fig.title ='The Asexual Flag'}
knitr::include_graphics("001%20assets/AsexualPrideFlag.svg")

Now since this replacement falls into the scenario where you don't need to keep track of the position you can remove those parts:

p := 1                                                ; remove
while (p := RegExMatch(txt, "iO)" regex, match, p)) { ; change...
while (RegExMatch(txt, "iO)" regex, match)) {         ; ...for
p += StrLen(tpl)                                      ; remove

The result will be the same.


Hope this clears things, I know it is a lot to read but if you have any questions just shoot.

@Gewerd-Strauss
Copy link

There is an issue:

Apparently, only nonempty options are valid, so any option that is not given cannot be inserted into the codeblock. Additionally, the settings block cannot end in a comma before the closing bracket.

My attempt was... futile, and I am not even sure why. I'll take a closer look tomorrow.

; #Requires Autohotkey v1.1+
ConvertSRC_SYNTAX("C:\Users\Claudius Main\Desktop\TempTemporal\Embed2\index.md")

ConvertSRC_SYNTAX(md_Path)
{
    if FileExist(md_Path)
        FileRead, buffer, % md_Path
    else
        buffer:=md_Path
    ;Clipboard:=buffer
    p := 1
    regex = <img src="(?<SRC>[^"]+)"  width="(?<WIDTH>[^"]*)" alt="(?<ALT>[^"]*)" title="(?<TITLE>[^"]*)" \/>
    while (p := RegExMatch(buffer, "iO)" regex, match, p)) {
        align := ""
        cap := match.alt
        src := strreplace(match.src,"%20",A_Space)
        title := match.title
        width := match.width
        options:=""
        if width
            options.="out.width='" width  
        if extra 
            options.=(options!=""?"', ":"") "out.extra='" extra 
        if align
            options.=(options!=""?"', ":"") "fig.align='" align 
        if cap
            options.=(options!=""?"', ":"") "fig.cap='" cap 
        if title
            options.=(options!=""?"', ":"") "fig.title='" title
        ;options:=StrReplace(options, SearchText [, ReplaceText, OutputVarCount, Limit := -1])
        ; out.width='%width%', out.extra='', fig.align='%align%', fig.cap='%alt%', fig.title ='%title%'
        if (options!="")
            options:=", " options "'"
        tpl =
            (LTrim

            ``````{r, echo=FALSE%options%}
            knitr::include_graphics("%src%")
            ``````

            )
        buffer := StrReplace(buffer, match[0], tpl)
        p += StrLen(tpl)
    }
    tpl=
    (LTrim
    
    ---
    ``````{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = FALSE)

    ``````
    
)
    buffer:=RegexReplace(buffer, "\n---",tpl,,,1)
    Clipboard:=buffer
    OutputDebug % buffer
    return buffer
}

index.md:

---
creation date: 2023-01-06 20:04
description: A test file
modification date: 2023-01-15 00:27
obsidianUIMode: source
tags:
- programming
---
   
This is the child file   
   
# Embed2   
   
Your modes, all markdown ones:     
**1** <img src="001%20assets/AsexualPrideFlag.png"  width="100" alt="The Asexual Flag" title="The Asexual Flag" />     
**2** <img src="001%20assets/AsexualPrideFlag.png"  width="100" alt="" title="" />     
   
//   
   
Wikilink-embeds:     
**5** ![](001%20assets/AsexualPrideFlag.png)     
   
//   
   
Wikilink-embeds with names:     
**7** <img src="001%20assets/AsexualPrideFlag.png"  width="" alt="Asexual Pride Flag" title="Asexual Pride Flag" />     
   
//   
   
Wikilink-embeds with sizing     
**9** <img src="001%20assets/AsexualPrideFlag.png"  width="100" alt="" title="" />     
   
//   
   
Wikilink-embeds with sizing and names     
**11** <img src="001%20assets/AsexualPrideFlag.png"  width="100" alt="Asexual Pride Flag" title="Asexual Pride Flag" />     
   
//   
   
Markdown-embeds:     
**13** ![](001%20assets/AsexualPrideFlag.png)     
   
//   
   
Markdown-embeds with names:     
**15** <img src="001%20assets/AsexualPrideFlag.png"  width="" alt="Asexual Pride Flag" title="Asexual Pride Flag" />     
   
//   
   
Markdown-embeds with sizing     
**17** <img src="001%20assets/AsexualPrideFlag.png"  width="100" alt="" title="" />     
   
//   
   
Markdown-embeds with sizing and names     
**19** <img src="001%20assets/AsexualPrideFlag.png"  width="100" alt="Asexual Pride Flag" title="Asexual Pride Flag" />     
   
All images with at **bolded numbers** are PNG's, all others SVG's.   
   
# EOF

The output index.rmd suggests that there is something not being placed correctly ending up replacing all other instances (or maybe it is not adjusted correctly, and now we cannot find them anymore cuz the pattern shifted? Idk, neither seems super logical when looking at my modifications)

@anonymous1184
Copy link
Author

extra and align are never defined.

if extra 
    options.=(options!=""?"', ":"") "out.extra='" extra 
if align
    options.=(options!=""?"', ":"") "fig.align='" align 

Generally, instead of using this:

options .= (options != "" ? "', " : "") "fig.align='" align 

You add everything that is needed and at the end of the loop you remove leftovers

options .= "fig.align='" align "',"
; ...
; All other additions to the `options` variable
; ...
options := RTrim(options, ",") ; Remove the last comma
tpl = ... ; create the template where %options% is used

Can I have a link with a copy of indeex.md? So I can do a test myself, because I don't really understand what you're trying to achieve.

Also, this:

``````{r, echo=FALSE%options%}

And this:

``````{r setup, include=FALSE}

Is invalid, the fenced blocks should be in its own line, different parser will produce a different result... most of them will fail.

https://www.markdownguide.org/extended-syntax/#fenced-code-blocks

Depending on your Markdown processor or editor, you’ll use three backticks (```) or three tildes (~~~) on the lines before and after the code block

The only word that optionally can follow the starting backticks is the language, so syntax highlighting can make sense of which highlighter to use.

Examples:

```ahk
hWnd := WinExist("ahk_exe Notepad.exe")
```

Will render:

hWnd := WinExist("ahk_exe Notepad.exe")

And:

```json
{"foo":123, "bar":"baz"}
```

Will become:

{"foo":123, "bar":"baz"}

@Gewerd-Strauss
Copy link

You add everything that is needed and at the end of the loop you remove leftovers

&

; Remove the last comma

The issue with that is that f.e.
{r, out.width='100', fig.cap='The Asexual Flag', fig.title=''} would error out and not render properly, because the codeblock contains empty commands.

Also, this:

``````{r, echo=FALSE%options%}

And this:

``````{r setup, include=FALSE}

Is invalid

But that is what we need to escape the backticks properly, so we end up with 3 ticks each side. And the syntax is correct for any Codeblocks in Rmarkdown:

grafik

Link to index.md

It's the initial file, it just has a different name because index.md is the autogen-name from obsidianhtml:
https://drive.google.com/file/d/1GmV0ZahIxcmXWliRG02IRvhjVgFy0ive/view?usp=sharing

Apparently you cannot attach md-files or zips to comments in gists, so google drive it is.
_vault.md is the original file before processing via ObsidianHTML just for reference
index.md is the src-containing one.

@Gewerd-Strauss
Copy link

Gewerd-Strauss commented Jan 15, 2023

Also I have an issue that I must search for and remove any potentially existing r setup-blocks as a precaution, but that should be doable. just need to remove all blocks starting with "r setup", then do a single regexreplace at the end of the yaml-header at the top of the file.

Should be fixed

@Gewerd-Strauss
Copy link

Gewerd-Strauss commented Jan 15, 2023

Also looks like I must open an issue on ObsidianHTML that maybe dots and quotes are not escaped when including images. Hmm. I'll take a look later. Actually, I have no idea what's going on, an image doesn't get detected by the CLI properly and I don't know why. LAter

@Gewerd-Strauss
Copy link

Gewerd-Strauss commented Jan 15, 2023

Bug found/unaware-of issue:

Source (ignore the braces being curly now, it happens because lintalist thinks it's a snippet. I am too lazy to change this every time, just consider them squared brackets):

NORMAL:  
!{{200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22: Phylogenetic Tree of the sequences mentioned in 45 Similar sequences}}  
Quotes:  
!{{200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22: Phylogenetic Tree of the sequences mentioned in "45 Similar sequences"}}  
DOT:  
!{{200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22: Phylogenetic Tree of the sequences mentioned in 4.5 Similar sequences}}  

Output by ObsidianHTML (dots in image titles are currently breaking the ObsidianHTML-script, it seems.):

---
creation date: 2023-01-15 13:00
modification date: 2023-01-15 13:01
tags: []
---
   
NORMAL:     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22: Phylogenetic Tree of the sequences mentioned in 45 Similar sequences" title="Figure 22: Phylogenetic Tree of the sequences mentioned in 45 Similar sequences" />     
Quotes:     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22: Phylogenetic Tree of the sequences mentioned in "45 Similar sequences"" title="Figure 22: Phylogenetic Tree of the sequences mentioned in "45 Similar sequences"" />     
DOT:     
> **obsidian-html error:** Error including file or not a markdown file 200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22: Phylogenetic Tree of the sequences mentioned in 4.5 Similar sequences.

Output by the conversion script:

---
creation date: 2023-01-15 13:00
modification date: 2023-01-15 13:01
tags: []
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)

```

   
NORMAL:     


```{r, fig.cap='Figure 22: Phylogenetic Tree of the sequences mentioned in 45 Similar sequences', fig.title='Figure 22: Phylogenetic Tree of the sequences mentioned in 45 Similar sequences'}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree %28actual Phylotree%29.PNG")
```

     
Quotes:     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22: Phylogenetic Tree of the sequences mentioned in "45 Similar sequences"" title="Figure 22: Phylogenetic Tree of the sequences mentioned in "45 Similar sequences"" />     
DOT:     
> **obsidian-html error:** Error including file or not a markdown file 200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22: Phylogenetic Tree of the sequences mentioned in 4.5 Similar sequences.

The question now is how to deal with quotes in image titles, as they are currently used for the regex.

If you want to decode is simple, you can either:

  • Search for %20 and replace it to space if only that's needed.
  • Search for %[0-9A-Z]{2} and replace with the appropriate character.
  • Use WinHttpRequest.DecodeURIComponent().

If you want the automated nature of the 3rd option but don't need the WinHttpRequest wrapper, you can simply use the HTMLFile COM object in a stand-alone function.

Suggests that at least the quotation-issue could be resolved. I'll take a look at your httprequest-lib (I think you made one a while ago) and see if I understand it.

Edit 15.01.2023 14:00:

I'm dumb. No point in doing this right now until I figure out how to fix the regex first, me dumbo. (ノಠ益ಠ)ノ彡┻━┻

@Gewerd-Strauss
Copy link

All in all, it seems like brackets, dots and quotes are giving errors so far. Quotes will be due to this script, the rest just doesn't convert properly using ObsidianHTML, I suspect. Not sure what's exactly going on, but here's a testset just in case you want it - so we save a set of timezone shenanigans:

https://drive.google.com/file/d/1KoBcNWB54AYeaOEKhxhw9iEwimx7wjQD/view?usp=sharing

@Gewerd-Strauss
Copy link

Update: Everything but the quotes has been fixed by recent commits towards said issue on the ObsidianHTML-repo. As the quoting is not an issue of ObsidianHTML itself, there's obviously nothing to be done there.

@anonymous1184
Copy link
Author

anonymous1184 commented Jan 15, 2023

But that is what we need to escape the backticks properly, so we end up with 3 ticks each side. And the syntax is correct for any Codeblocks in Rmarkdown:

I know that you need to escape a backtick with a backtick. What I meant is that you need to replace this:

``````{r, echo=FALSE%options%}
knitr::include_graphics("%src%")
``````

For this:

``````
{r, echo=FALSE%options%}
knitr::include_graphics("%src%")
``````

Ie, you need to keep the backticks in its own line, read carefully the wording:

... use three backticks ... on the lines before and after the code block

Backticks, lines, before and after the code block.

https://www.markdownguide.org/extended-syntax/#fenced-code-blocks

The next topic covers the highlighting:

To add syntax highlighting, specify a language next to the backticks before the fenced code block.

https://www.markdownguide.org/extended-syntax/#syntax-highlighting

And before jumping to other topic, that looks plain wrong... shouldn't be a comma there to separate the echo property from all the other properties the %options% var adds?, for example:

``````
{r, echo=FALSE, %options%}
knitr::include_graphics("%src%")
``````

If that is R, then it needs a comma.



And after seeing the file, I think I know what you want to do: test with different characters how the AHK script will fare.

One of the issues is that the markdown in itself is invalid. The proper image format is as follows:

![alt text](URL "title")

For an image with a link:

[![alt text](img URL)](link URL "title")

<!-- Which is just wrapping the image in a link -->

 ![alt text](img URL)                    <!-- Regular image -->
[![alt text](img URL)](link URL "title") <!-- Image as a link -->
[                    ](                ) <!-- Common link -->

The other issue is that you need proper encoding/decoding of the characters. The img tag must adhere to the conventions of the HTML markup (encode all that is needed). Here is the whole enchilada on the why, how and when:

https://wikiless.org/wiki/Percent-encoding



So after fixing the input data (markdown file) and tweaking the script, I think is working as you wanted.

However, the RegEx works for img tags, not for Markdown image syntax (brackets). You need to create a new function to deal with just that.

I included WinHttpRequest, but again you can make a stand-alone function. BTW, since many characters require to be encoded in each attribute (src, alt, title), and whatever you are doing doesn't support percentage-encoding, I used the decode method on each.

Anyway, to construct the options, I went with the order in the img tag: src, width, alt and title. align and extra are never defined, so I commented them because I don't know what's what with those.



Files:

  • fixed.md is the fixed version of index.md.
  • obsidian.ahk is the script with the function.
fixed.md
---
creation date: 2023-01-15 13:00
modification date: 2023-01-15 14:26
tags:
- programming
---

Normal:
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 45 Similar sequences" title="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 45 Similar sequences" />

!:
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4%215 Similar sequences" title="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4%215 Similar sequences" />

":
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22%3A Phylogenetic Tree of the sequences mentioned in %2245 Similar sequences%22" title="Figure 22%3A Phylogenetic Tree of the sequences mentioned in %2245 Similar sequences%22" />

$:
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4%245 Similar sequences" title="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4%245 Similar sequences" />

%:
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4%255 Similar sequences" title="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4%255 Similar sequences" />

&:
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4%265 Similar sequences" title="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4%265 Similar sequences" />

/:
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4%2F5 Similar sequences" title="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4%2F5 Similar sequences" />

():
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4%28%295 Similar sequences" title="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4%28%295 Similar sequences" />

[]:
![Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4\[\]5 Similar sequences](200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG "Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4[]5 Similar sequences")

{}:
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4{}5 Similar sequences" title="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4{}5 Similar sequences" />

?:
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4%3F5 Similar sequences" title="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4%3F5 Similar sequences" />

.:
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4.5 Similar sequences" title="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4.5 Similar sequences" />

,:
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4,5 Similar sequences" title="Figure 22%3A Phylogenetic Tree of the sequences mentioned in 4,5 Similar sequences" />
Obsidian.ahk
#Warn
#Requires Autohotkey v1.1+

OutputDebug % ConvertSRC_SYNTAX(A_ScriptDir "\index~.md")

return ; End of auto-execute

#Include <WinHttpRequest>

ConvertSRC_SYNTAX(PathOrContent) {
    if (FileExist(PathOrContent))
        FileRead buffer, % PathOrContent
    else
        buffer := PathOrContent
    p := 1
    regex = <img src="(?<SRC>[^"]+)"  width="(?<WIDTH>[^"]*)" alt="(?<ALT>[^"]*)" title="(?<TITLE>[^"]*)" \/>
    while (p := RegExMatch(buffer, "iO)" regex, match, p)) {
        options := ""
        src := WinHttpRequest.DecodeUriComponent(match.src)
        options .= "fig.src='" src "', "
        if (match.width)
            options .= "out.width='" match.width "', "
        if (match.alt)
            options .= "fig.cap='" WinHttpRequest.DecodeUriComponent(match.alt) "', "
        if (match.title)
            options .= "fig.title='" WinHttpRequest.DecodeUriComponent(match.title) "', "
        /* This is undefined
        if (extra)
            options .= "out.extra='" extra "', "
        if (align)
            options .= "fig.align='" align "', "
        */
        options := RTrim(options, ", ")
        tpl =
            (LTrim
            ``````
            {r, echo=FALSE, %options%}
            knitr::include_graphics("%src%")
            ``````
            )
        buffer := StrReplace(buffer, match[0], tpl)
        p += StrLen(tpl)
    }
    tpl =
        (LTrim

        ---
        ``````
        {r setup, include=FALSE}
        knitr::opts_chunk$set(echo = FALSE)
        ``````
        )
    buffer := RegexReplace(buffer, "\n---", tpl,,, 1)
    return buffer
}

@Gewerd-Strauss
Copy link

Code chunk shit.

I disagree, on the basis that I have written multiple reports in it, can find a variety of documentation* in support of it and have working examples on file :P
I am aware that normal code blocks look different, but given that this is quite literally the required format, I will continue assuming it being the correct format to use for RMarkdown.


So after fixing the input data (markdown file) and tweaking the script, I think is working as you wanted.

I checked out your solution, but it will obviously still fail on quotes. The simple solution would be to decide to only use ' in figure titles/alts, because that character will not disrupt the regex and can then be switched out for a normal quotation mark while building the options-string:

if (match.alt)
          options .= "fig.cap='" strreplace(WinHttpRequest.DecodeUriComponent(match.alt),"'","""") "', "
if (match.title)
          options .= "fig.title='" strreplace(WinHttpRequest.DecodeUriComponent(match.title),"'","""") "', "

The complicated, but overall better solution involves adapting the regex to not fail out on those.


I also realised that percentage signs are stripped by HTTPRequest, so I'll need to figure out how to escape those as well.

title/decod title/wiwdth/alt/decod alt:
grafik


  options .= "fig.src='" src "', "

Removed, the src does not belong in the options-param as far as I know.


/* This is undefined
      if (extra)
          options .= "out.extra='" extra "', "
      if (align)
          options .= "fig.align='" align "', "
      */

I will later probably comment in extra, because RMD is quirky. The arg is apparently needed in some code blocks to format properly when going to pdf (because that conversion employs latex, and tf do I know why that is the case ¯\_(ツ)_/¯, I just read so).


*Consider

which are published by the team (particularly Yihui Xie) behind RMarkdown.

@Gewerd-Strauss
Copy link

Addendum on the %-sign: those are the outputs by obsidianhtml, so that util doesn't escape/encode it properly either. So yea. As O understand it,for the percentage it should be simply a question of encoding it properly. However, I'm not sure how to do so in a simple manner. So far as I understand it, winhttpreq.decodeuri/encodeuri don't like getting full strings fed, but instead you'd have to parse the string, find all to-be-encoded characters, get their encodings and replace in place.

But then again, I'm not entirely sure either and you're probably way more knowledgeable on any one of these topics than me: P

@anonymous1184
Copy link
Author

Code chunk shit.

I disagree, on the basis that I have written multiple reports in it, can find a variety of documentation* in support of it and have working examples on file :P I am aware that normal code blocks look different, but given that this is quite literally the required format, I will continue assuming it being the correct format to use for RMarkdown.

Hahaha, never said that, and I didn't even know they have a name, what they were, let alone they used a proprietary Markdown style.


... your solution, but it will obviously still fail on quotes.

To me looks fine, this would be the result for the quotes (after you know, putting the options back next to the backticks and removing the unneeded src attribute):

```{r, echo=FALSE, fig.cap='Figure 22: Phylogenetic Tree of the sequences mentioned in "45 Similar sequences"', fig.title='Figure 22: Phylogenetic Tree of the sequences mentioned in "45 Similar sequences"'}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```

Where is the issue? The double quotes are properly enclosed into single quotes. This is the same, just formatted:

{
    r,
    echo=FALSE,
    fig.cap='Figure 22: Phylogenetic Tree of the sequences mentioned in "45 Similar sequences"',
    fig.title='Figure 22: Phylogenetic Tree of the sequences mentioned in "45 Similar sequences"'
}

I also realised that percentage signs are stripped by HTTPRequest, so I'll need to figure out how to escape those as well.

Nothing is stripped, the decodeUriComponent()msdn from JavaScript only converts from the percetage-escaped values to the character they represent.

You can't simply write invalid HTML and expect it to work fine:

<!--
Given the file: 100%.png
-->
<img src="./100%.png" title="This image represents 100%">   <!-- Invalid -->
<img src="./100%25.png" title="This image represents 100%"> <!-- Valid -->

If you want to write properly escaped HTML, I recommend you to use encodeUriComponent()msdn. For example is you want to see which and how the 94 printed ASCII values get encoded:

loop 94 {
    chr := Chr(32 + A_Index)
    enc := WinHttpRequest.EncodeUriComponent(chr)
    enc := Format("{: 3}", enc)
    OutputDebug % chr " -> " enc
}

Or even to write a src attribute for a tag:

path := "images\100% equivalency.png" ; System path
src := StrReplace(path, "\", "/")     ; Web path
src := WinHttpRequest.EncodeUri(src)  ; Encoding
OutputDebug % "<img src=""" src """>" ; <img src="images/100%25%20equivalency.png">

Here is the difference between encode/decodeUri() and encode/decodeUriComponent():

https://stackoverflow.com/a/747700/11918484


And this like many others, this was a case of assumption; I assumed you wanted to always make sense of the src attribute (which is a URI). But in here we deal with different parts of the equation (sorry, you need to check these):

  • URI
    • URL
  • HTML element
    • HTML attribute
    • HTML text
      • HTML entities

A full URI is encoded with some rules, the keys/values of the query part of a URI are encoded with others and attributes/text use entities.

Full URI                              -> UriEncode(full URI)
http://example.com/my file.html#hello -> http://example.com/my%20file.html#hello

foo value                    -> UriEncodeComponent(pt#1)
http://example.com/?foo=pt#1 -> http://example.com/?foo=pt%231

paragraph text          -> Entities(paragraph text)
<p>test "test" test</p> -> <p>test &quot;test&quot; test</p>

Quotes are always encoded in URIs while in attributes/text, entities are used (&quot;).


I know it suddenly changed but you know, the more you explain the more I understand what you want to do.

Here are my files (removed the dependencies and added small functions to simplify things).

  • fixed.md - Standard markdown with properly encoded HTML.
  • obsidian.ahk - The latest conversion function with helper functions.

The latter will create a converted.md, that I want to believe is the expected result.

fixed.md
---
creation date: 2023-01-15 13:00
modification date: 2023-01-15 14:26
tags:
- programming
---

Normal:
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22: Phylogenetic Tree of the sequences mentioned in 45 Similar sequences" title="Figure 22: Phylogenetic Tree of the sequences mentioned in 45 Similar sequences" />

!:
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22: Phylogenetic Tree of the sequences mentioned in 4!5 Similar sequences" title="Figure 22: Phylogenetic Tree of the sequences mentioned in 4!5 Similar sequences" />

":
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22: Phylogenetic Tree of the sequences mentioned in &quot;45 Similar sequences&quot;" title="Figure 22: Phylogenetic Tree of the sequences mentioned in &quot;45 Similar sequences&quot;" />

$:
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22: Phylogenetic Tree of the sequences mentioned in 4$5 Similar sequences" title="Figure 22: Phylogenetic Tree of the sequences mentioned in 4$5 Similar sequences" />

%:
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22: Phylogenetic Tree of the sequences mentioned in 4%5 Similar sequences" title="Figure 22: Phylogenetic Tree of the sequences mentioned in 4%5 Similar sequences" />

&:
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22: Phylogenetic Tree of the sequences mentioned in 4&amp;5 Similar sequences" title="Figure 22: Phylogenetic Tree of the sequences mentioned in 4&amp;5 Similar sequences" />

/:
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22: Phylogenetic Tree of the sequences mentioned in 4/5 Similar sequences" title="Figure 22: Phylogenetic Tree of the sequences mentioned in 4/5 Similar sequences" />

():
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22: Phylogenetic Tree of the sequences mentioned in 4()5 Similar sequences" title="Figure 22: Phylogenetic Tree of the sequences mentioned in 4()5 Similar sequences" />

[]:
![Figure 22: Phylogenetic Tree of the sequences mentioned in 4\[\]5 Similar sequences](200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG "Figure 22: Phylogenetic Tree of the sequences mentioned in 4[]5 Similar sequences")

{}:
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22: Phylogenetic Tree of the sequences mentioned in 4{}5 Similar sequences" title="Figure 22: Phylogenetic Tree of the sequences mentioned in 4{}5 Similar sequences" />

?:
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22: Phylogenetic Tree of the sequences mentioned in 4?5 Similar sequences" title="Figure 22: Phylogenetic Tree of the sequences mentioned in 4?5 Similar sequences" />

.:
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22: Phylogenetic Tree of the sequences mentioned in 4.5 Similar sequences" title="Figure 22: Phylogenetic Tree of the sequences mentioned in 4.5 Similar sequences" />

,:
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22: Phylogenetic Tree of the sequences mentioned in 4,5 Similar sequences" title="Figure 22: Phylogenetic Tree of the sequences mentioned in 4,5 Similar sequences" />
obsidian.ahk
#Warn
#Requires Autohotkey v1.1.10+

converted := ConvertSRC_SYNTAX(A_ScriptDir "\fixed.md")
OutputDebug % converted
FileOpen(A_ScriptDir "\converted.md", 0x1).Write(converted)


return ; End of auto-execute


ConvertSRC_SYNTAX(PathOrContent) {
    if (FileExist(PathOrContent))
        FileRead buffer, % PathOrContent
    else
        buffer := PathOrContent
    p := 1
    ;@ahk-neko-ignore 1 line
    regex = <img src="(?<SRC>[^"]+)"  width="(?<WIDTH>[^"]*)" alt="(?<ALT>[^"]*)" title="(?<TITLE>[^"]*)" \/>
    while (p := RegExMatch(buffer, "iO)" regex, match, p)) {
        options := ""
        src := DecodeUriComponent(match.src)
        if (match.width)
            options .= "out.width='" match.width "', "
        if (match.alt)
            options .= "fig.cap='" DecodeEntities(match.alt) "', "
        if (match.title)
            options .= "fig.title='" DecodeEntities(match.title) "', "
        options := RTrim(options, ", ")
        tpl =
            (LTrim
            ``````{r, echo=FALSE, %options%}
            knitr::include_graphics("%src%")
            ``````
            )
        buffer := StrReplace(buffer, match[0], tpl)
        p += StrLen(tpl)
    }
    tpl =
        (LTrim
        ---
        ``````{r setup, include=FALSE}
        knitr::opts_chunk$set(echo = FALSE)
        ``````
        )
    buffer := RegexReplace(buffer, "\n---", "`n" tpl,,, 1)
    return buffer
}

DecodeEntities(sText) {
    return _Decode(sText, 1)
}

DecodeUriComponent(sText) {
    return _Decode(sText, 2)
}

; nMode
; 1 = HTML entity decode
; 2 = decodeURIComponent
_Decode(sText, nMode) {
    static document := ""
    if (document = "") {
        document := ComObjCreate("HTMLFile")
        document.write("<meta http-equiv='X-UA-Compatible' content='IE=Edge'>")
    }
    switch (nMode) {
        case 1:
            document.write(sText)
            txt := document.documentElement.innerText
            document.close()
        case 2:
            txt := document.parentWindow.decodeURIComponent(sText)
        default:
            txt := "Unknown " A_ThisFunc "() mode."
    }
    return txt
}

And if I failed again, maybe you should try and explain what are your trying to achieve :P

@Gewerd-Strauss
Copy link

never said that, and I didn't even know they have a name, what they were,

Ah crap, I'm sorry for not mentioning this, that was my bad. I thought I did, but I also learned that I often cannot trust my own memory on such things - sadly. I'm sorry.

The clear overview:

Below you can find the raw output from ObsidianHTML. This is what we need to work with when parsing and converting. So we either need to preprocess and parse this and manually convert " to &quot; (and so on for other potential characters that will bring issues) in order to get properly encoded attributes (as I understand your explanation, correct me if I'm wrong), or... I am not sure. That might be the only option, but sounds like a pain to do as well - but maybe it's not and I just don't know that.

I could ask ObsidianHTML for a setting to do a complete encoding so we start out with properly formatted html in our src à la your fixed.md. In that case, this current solution should be all we need, (if that makes sense to you. I got a mild bit lost if I am completely honest.)

However, given that they are actually careful about scope creep, and this is a specific question for a niche solution that's actually way outside the projects' boundaries, I am not sure that would be the sensible path to take.

So. Just looking at the relevant section of ObsidianHTML's output (" and '):

Quotes:     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_3: Phylogenetic Tree of the sequences mentioned in "45 Similar sequences"" title="Figure 22_3: Phylogenetic Tree of the sequences mentioned in "45 Similar sequences"" />     
Other Quotes:     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_4: Phylogenetic Tree of the sequences mentioned in '45 Similar sequences'" title="Figure 22_4: Phylogenetic Tree of the sequences mentioned in '45 Similar sequences'" />

Running through the script results in

Quotes:     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_3: Phylogenetic Tree of the sequences mentioned in "45 Similar sequences"" title="Figure 22_3: Phylogenetic Tree of the sequences mentioned in "45 Similar sequences"" />     
Other Quotes:     


```{r, echo=FALSE, fig.cap='Figure 22_4: Phylogenetic Tree of the sequences mentioned in '45 Similar sequences'', fig.title='Figure 22_4: Phylogenetic Tree of the sequences mentioned in '45 Similar sequences''}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```

This has two problems. Double quotes are not detected and converter, and single quotes are not escaped and cause mayhem.
But we are looking to get

Quotes:     


```{r, echo=FALSE, fig.cap='Figure 22_4: Phylogenetic Tree of the sequences mentioned in "45 Similar sequences"', fig.title='Figure 22_4: Phylogenetic Tree of the sequences mentioned in "45 Similar sequences"'}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```


Other Quotes:     


```{r, echo=FALSE, fig.cap='Figure 22_4: Phylogenetic Tree of the sequences mentioned in \'45 Similar sequences\'', fig.title='Figure 22_4: Phylogenetic Tree of the sequences mentioned in \'45 Similar sequences\''}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```

To summarise the required steps

  • in-text single-quotes ' must be escaped via backslash when building the fig.title- and fig.caption-attributes.
  • in-text double quotes " are not currently converted because I cannot generate the fixed.md syntax you are basing the third iteration of ConvertSRC_SYNTAX upon from the ObsidianHTML-output, and thus the codeblock is not built. Check the first codeblock in this reply for the format we start with.

(We should start naming the function :P)


P.S.: How do I make these codeblocks collapsible like your fixed.md?



ObsidianHTML's output:

---
creation date: 2023-01-15 13:00
modification date: 2023-01-17 11:06
tags:
- programming
---
   
NORMAL:     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="12" alt="Figure 22_1: Phylogenetic Tree of the sequences mentioned in 45 Similar sequences" title="Figure 22_1: Phylogenetic Tree of the sequences mentioned in 45 Similar sequences" />     
Exclamation mark:     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_2: Phylogenetic Tree of the sequences mentioned in 4!5 Similar sequences" title="Figure 22_2: Phylogenetic Tree of the sequences mentioned in 4!5 Similar sequences" />     
Quotes:     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_3: Phylogenetic Tree of the sequences mentioned in "45 Similar sequences"" title="Figure 22_3: Phylogenetic Tree of the sequences mentioned in "45 Similar sequences"" />     
Other Quotes:     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_4: Phylogenetic Tree of the sequences mentioned in '45 Similar sequences'" title="Figure 22_4: Phylogenetic Tree of the sequences mentioned in '45 Similar sequences'" />     
$:     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_5: Phylogenetic Tree of the sequences mentioned in 4$5 Similar sequences" title="Figure 22_5: Phylogenetic Tree of the sequences mentioned in 4$5 Similar sequences" />     
%:     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_6: Phylogenetic Tree of the sequences mentioned in 4%5 Similar sequences" title="Figure 22_6: Phylogenetic Tree of the sequences mentioned in 4%5 Similar sequences" />     
&:     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_7: Phylogenetic Tree of the sequences mentioned in 4&5 Similar sequences" title="Figure 22_7: Phylogenetic Tree of the sequences mentioned in 4&5 Similar sequences" />     
/:     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_8: Phylogenetic Tree of the sequences mentioned in 4/5 Similar sequences" title="Figure 22_8: Phylogenetic Tree of the sequences mentioned in 4/5 Similar sequences" />     
():     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_9: Phylogenetic Tree of the sequences mentioned in (4.5 Similar sequences)" title="Figure 22_9: Phylogenetic Tree of the sequences mentioned in (4.5 Similar sequences)" />     
\[\]:     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_10: Phylogenetic Tree of the sequences mentioned in 4.5 [Similar sequences] " title="Figure 22_10: Phylogenetic Tree of the sequences mentioned in 4.5 [Similar sequences] " />     
{}:     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_11: Phylogenetic Tree of the sequences mentioned in 4{}5 Similar sequences" title="Figure 22_11: Phylogenetic Tree of the sequences mentioned in 4{}5 Similar sequences" />     
Question mark:     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_12: Phylogenetic Tree of the sequences mentioned in 4?5 Similar sequences" title="Figure 22_12: Phylogenetic Tree of the sequences mentioned in 4?5 Similar sequences" />     
   
DOT:     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_13: Phylogenetic Tree of the sequences mentioned in 4.5 Similar sequences" title="Figure 22_13: Phylogenetic Tree of the sequences mentioned in 4.5 Similar sequences" />     
comma:     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_14: Phylogenetic Tree of the sequences mentioned in 4,5 Similar sequences" title="Figure 22_14: Phylogenetic Tree of the sequences mentioned in 4,5 Similar sequences" />

ObsidianHTML's input:

---
creation date: "2023-01-15 13:00"
modification date: "2023-01-17 11:06"
tags: programming
---
NORMAL:  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_1: Phylogenetic Tree of the sequences mentioned in 45 Similar sequences|12]]  
Exclamation mark:  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_2: Phylogenetic Tree of the sequences mentioned in 4!5 Similar sequences]]  
Quotes:  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_3: Phylogenetic Tree of the sequences mentioned in "45 Similar sequences"]]  
Other Quotes:  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_4: Phylogenetic Tree of the sequences mentioned in '45 Similar sequences']]  
$:  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_5: Phylogenetic Tree of the sequences mentioned in 4$5 Similar sequences]]  
%:  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_6: Phylogenetic Tree of the sequences mentioned in 4%5 Similar sequences]]  
&:  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_7: Phylogenetic Tree of the sequences mentioned in 4&5 Similar sequences]]  
/:  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_8: Phylogenetic Tree of the sequences mentioned in 4/5 Similar sequences]]  
():  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_9: Phylogenetic Tree of the sequences mentioned in (4.5 Similar sequences)]]  
\[\]:  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_10: Phylogenetic Tree of the sequences mentioned in 4.5 [Similar sequences] ]]  
{}:  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_11: Phylogenetic Tree of the sequences mentioned in 4{}5 Similar sequences]]  
Question mark:  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_12: Phylogenetic Tree of the sequences mentioned in 4?5 Similar sequences]]  

DOT:  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_13: Phylogenetic Tree of the sequences mentioned in 4.5 Similar sequences]]  
comma:  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_14: Phylogenetic Tree of the sequences mentioned in 4,5 Similar sequences]]  

@anonymous1184
Copy link
Author

Let's do the following: craft a Markdown that you know the ObsidianHTML will be troublesome, create the RMarkdown and manually adjust what's needed.

I think I have all that I need, but just so to be sure.


To collapse content:

<details>
  <summary>Title</summary>
  <p>Content (this will be collapsed).</p>
</details>

Rendered:

Title

Content (this will be collapsed).

If nesting code blocks, a blank line after sumary is required.

<details>
  <summary>Example of <code>script.ahk</code></summary>

```ahk
MsgBox Hello World!
```
</details>

Rendered:

Example of script.ahk
MsgBox Hello World!

VScode.md provides a good example (raw source).

@Gewerd-Strauss
Copy link

Here you go. I think this is what you are asking for.

Obsidian Source
---
creation date: "2023-01-15 13:00"
modification date: "2023-01-18 08:55"
tags: programming
---

# Chapter 1: Successfully converted by ObsidianHTML, parsing failed by _ConvertSRC_SYNTAX_V3_:

Quotes:  
- Start  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|"Figure 22_4: Phylogenetic" Tree of the sequences mentioned in 45 Similar sequences]]  
- Middle  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_4: "Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences]]  
- End  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_4: Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences"]]  

Other Quotes:  

- Start  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|'Figure 22_4: Phylogenetic' Tree of the sequences mentioned in 45 Similar sequences]]  
- Middle  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_4: 'Phylogenetic Tree of the sequences mentioned' in 45 Similar sequences]]  
- End  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_4: Phylogenetic Tree of the sequences mentioned' in 45 Similar sequences']]  
ObsidianHTML-Output
---
creation date: 2023-01-15 13:00
modification date: 2023-01-18 08:55
tags:
- programming
---
   
# Chapter 1: Successfully converted by ObsidianHTML, parsing failed by _ConvertSRC_SYNTAX_V3_:   
   
Quotes:     
   
- Start     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt=""Figure 22_4: Phylogenetic" Tree of the sequences mentioned in 45 Similar sequences" title=""Figure 22_4: Phylogenetic" Tree of the sequences mentioned in 45 Similar sequences" />     
   
- Middle     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_4: "Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences" title="Figure 22_4: "Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences" />     
   
- End     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_4: Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences"" title="Figure 22_4: Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences"" />     
   
Other Quotes:     
   
   
- Start     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="'Figure 22_4: Phylogenetic' Tree of the sequences mentioned in 45 Similar sequences" title="'Figure 22_4: Phylogenetic' Tree of the sequences mentioned in 45 Similar sequences" />     
   
- Middle     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_4: 'Phylogenetic Tree of the sequences mentioned' in 45 Similar sequences" title="Figure 22_4: 'Phylogenetic Tree of the sequences mentioned' in 45 Similar sequences" />     
   
- End     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_4: Phylogenetic Tree of the sequences mentioned' in 45 Similar sequences'" title="Figure 22_4: Phylogenetic Tree of the sequences mentioned' in 45 Similar sequences'" />
And desired RMarkdown format (tested to knit successsfully to html and docx, and with a weird bug to pdf that I'm going to ignore for now)
---
creation date: "2023-01-15 13:00"
modification date: "2023-01-18 08:55"
tags: programming
output:
  html_document:
    df_print: paged
  word_document: default
  pdf_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

   
# Chapter 1: Successfully converted by ObsidianHTML, parsing failed by _ConvertSRC_SYNTAX_V3_:   
   
QuotesQuotes:     
  
- Start of figure title     


```{r, echo=FALSE, fig.cap='"Figure 22_4: Phylogenetic" Tree of the sequences mentioned in 45 Similar sequences', fig.title='"Figure 22_4: Phylogenetic" Tree of the sequences mentioned in 45 Similar sequences'}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```



- Middle of figure title     


```{r, echo=FALSE, fig.cap='Figure 22_4: "Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences', fig.title='Figure 22_4: "Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences'}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```



- End of figure title     


```{r, echo=FALSE, fig.cap='Figure 22_4: Phylogenetic Tree of the sequences mentioned in" 45 Similar sequences"', fig.title='Figure 22_4: Phylogenetic Tree of the sequences mentioned in" 45 Similar sequences"'}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```


Other Quotes:     
  
  
- Start     


```{r, echo=FALSE, fig.cap='\'Figure 22_4: Phylogenetic\' Tree of the sequences mentioned in 45 Similar sequences', fig.title='\'Figure 22_4: Phylogenetic\' Tree of the sequences mentioned in 45 Similar sequences'}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```



- Middle     


```{r, echo=FALSE, fig.cap='Figure 22_4: \'Phylogenetic Tree of the sequences mentioned\' in 45 Similar sequences', fig.title='Figure 22_4: \'Phylogenetic Tree of the sequences mentioned\' in 45 Similar sequences'}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```



- End     


```{r, echo=FALSE, fig.cap='Figure 22_4: Phylogenetic Tree of the sequences mentioned\' in 45 Similar sequences\'', fig.title='Figure 22_4: Phylogenetic Tree of the sequences mentioned\' in 45 Similar sequences\''}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```

I also tested that width parameters still work (obviously also manually done, cuz all of this is manual.)

Obsidian Source (with scaling)
---
creation date: "2023-01-15 13:00"
modification date: "2023-01-18 09:19"
tags: programming
---

# Chapter 1: Successfully converted by ObsidianHTML, parsing failed by _ConvertSRC_SYNTAX_V3_:

Quotes:  
- Start  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|"Figure 22_4: Phylogenetic" Tree of the sequences mentioned in 45 Similar sequences|200]]  
- Middle  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_4: "Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences|200]]  
- End  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_4: Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences"|200]]  

Other Quotes:  

- Start  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|'Figure 22_4: Phylogenetic' Tree of the sequences mentioned in 45 Similar sequences|200]]  
- Middle  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_4: 'Phylogenetic Tree of the sequences mentioned' in 45 Similar sequences|200]]  
- End  
![[200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).png|Figure 22_4: Phylogenetic Tree of the sequences mentioned' in 45 Similar sequences'|200]]  
ObsidianHTML-Output (with scaling)
---
creation date: 2023-01-15 13:00
modification date: 2023-01-18 09:19
tags:
- programming
---
   
# Chapter 1: Successfully converted by ObsidianHTML, parsing failed by _ConvertSRC_SYNTAX_V3_:   
   
Quotes:     
   
- Start     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="200" alt=""Figure 22_4: Phylogenetic" Tree of the sequences mentioned in 45 Similar sequences" title=""Figure 22_4: Phylogenetic" Tree of the sequences mentioned in 45 Similar sequences" />     
   
- Middle     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="200" alt="Figure 22_4: "Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences" title="Figure 22_4: "Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences" />     
   
- End     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="200" alt="Figure 22_4: Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences"" title="Figure 22_4: Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences"" />     
   
Other Quotes:     
   
   
- Start     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="200" alt="'Figure 22_4: Phylogenetic' Tree of the sequences mentioned in 45 Similar sequences" title="'Figure 22_4: Phylogenetic' Tree of the sequences mentioned in 45 Similar sequences" />     
   
- Middle     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="200" alt="Figure 22_4: 'Phylogenetic Tree of the sequences mentioned' in 45 Similar sequences" title="Figure 22_4: 'Phylogenetic Tree of the sequences mentioned' in 45 Similar sequences" />     
   
- End     
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="200" alt="Figure 22_4: Phylogenetic Tree of the sequences mentioned' in 45 Similar sequences'" title="Figure 22_4: Phylogenetic Tree of the sequences mentioned' in 45 Similar sequences'" />
And desired RMarkdown format (with scaling)
---
creation date: "2023-01-15 13:00"
modification date: "2023-01-18 08:55"
tags: programming
output:
  word_document: default
  html_document:
    df_print: paged
  pdf_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

   
# Chapter 1: Successfully converted by ObsidianHTML, parsing failed by _ConvertSRC_SYNTAX_V3_:   
   
QuotesQuotes:     
  
- Start of figure title     


```{r, echo=FALSE, out.width='200', fig.cap='"Figure 22_4: Phylogenetic" Tree of the sequences mentioned in 45 Similar sequences', fig.title='"Figure 22_4: Phylogenetic" Tree of the sequences mentioned in 45 Similar sequences'}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```



- Middle of figure title     


```{r, echo=FALSE, out.width='200', fig.cap='Figure 22_4: "Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences', fig.title='Figure 22_4: "Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences'}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```



- End of figure title     


```{r, echo=FALSE, out.width='200', fig.cap='Figure 22_4: Phylogenetic Tree of the sequences mentioned in" 45 Similar sequences"', fig.title='Figure 22_4: Phylogenetic Tree of the sequences mentioned in" 45 Similar sequences"'}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```


Other Quotes:     
  
  
- Start     


```{r, echo=FALSE, out.width='200', fig.cap='\'Figure 22_4: Phylogenetic\' Tree of the sequences mentioned in 45 Similar sequences', fig.title='\'Figure 22_4: Phylogenetic\' Tree of the sequences mentioned in 45 Similar sequences'}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```



- Middle     


```{r, echo=FALSE, out.width='200', fig.cap='Figure 22_4: \'Phylogenetic Tree of the sequences mentioned\' in 45 Similar sequences', fig.title='Figure 22_4: \'Phylogenetic Tree of the sequences mentioned\' in 45 Similar sequences'}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```



- End     


```{r, echo=FALSE, out.width='200', fig.cap='Figure 22_4: Phylogenetic Tree of the sequences mentioned\' in 45 Similar sequences\'', fig.title='Figure 22_4: Phylogenetic Tree of the sequences mentioned\' in 45 Similar sequences\''}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```

@anonymous1184
Copy link
Author

I'm gonna work out the files, as the RMarkdown does not come from the ObsidianHTML. They are pretty different.

For example, the headers are different.

Also, in the ObsidianHTML you have:

Quotes:

- Start

While in the RMarkdown:

QuotesQuotes:     
  
- Start of figure title     

Let's hope my modifications don't get in the way.

If you want to do it properly:

  • Create your markdown.
  • Export it in Obsidian.
  • Convert it to RMarkdown.
  • Fix the RMakdown.

@anonymous1184
Copy link
Author

All set, the only difference between the output and the desired output is in the Quotes/End, but that is because you did it manually. I only adjusted the description and space between each block, the blocks themselves I leave as they were.

20230119005829

You can run the AHK script and then see the diff. If you have a folder/workspace, just bring the console (Ctrl+`) and type:

vscode --diff ObsidianHTML-Output.md converted.md

Otherwise, use the full paths for the files.

ObsidianHTML-Output.md
---
creation date: "2023-01-15 13:00"
modification date: "2023-01-18 08:55"
tags: programming
output:
  html_document:
    df_print: paged
  word_document: default
  pdf_document: default
---

# Chapter 1: Successfully converted by ObsidianHTML, parsing failed by _ConvertSRC_SYNTAX_V3_:

Quotes:

- Start
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt=""Figure 22_4: Phylogenetic" Tree of the sequences mentioned in 45 Similar sequences" title=""Figure 22_4: Phylogenetic" Tree of the sequences mentioned in 45 Similar sequences" />

- Middle
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_4: "Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences" title="Figure 22_4: "Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences" />

- End
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_4: Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences"" title="Figure 22_4: Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences"" />

Other Quotes:

- Start
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="'Figure 22_4: Phylogenetic' Tree of the sequences mentioned in 45 Similar sequences" title="'Figure 22_4: Phylogenetic' Tree of the sequences mentioned in 45 Similar sequences" />

- Middle
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_4: 'Phylogenetic Tree of the sequences mentioned' in 45 Similar sequences" title="Figure 22_4: 'Phylogenetic Tree of the sequences mentioned' in 45 Similar sequences" />

- End
<img src="200%20University/04/BE22%20Bioinformatics/Task%207%20Phylogenetic%20Tree/GuideTree%20%28actual%20Phylotree%29.PNG"  width="" alt="Figure 22_4: Phylogenetic Tree of the sequences mentioned' in 45 Similar sequences'" title="Figure 22_4: Phylogenetic Tree of the sequences mentioned' in 45 Similar sequences'" />
Desired RMarkdown.md
---
creation date: "2023-01-15 13:00"
modification date: "2023-01-18 08:55"
tags: programming
output:
  html_document:
    df_print: paged
  word_document: default
  pdf_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

# Chapter 1: Successfully converted by ObsidianHTML, parsing failed by _ConvertSRC_SYNTAX_V3_:

Quotes:

- Start
```{r, echo=FALSE, fig.cap='"Figure 22_4: Phylogenetic" Tree of the sequences mentioned in 45 Similar sequences', fig.title='"Figure 22_4: Phylogenetic" Tree of the sequences mentioned in 45 Similar sequences'}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```

- Middle
```{r, echo=FALSE, fig.cap='Figure 22_4: "Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences', fig.title='Figure 22_4: "Phylogenetic Tree of the sequences mentioned" in 45 Similar sequences'}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```

- End
```{r, echo=FALSE, fig.cap='Figure 22_4: Phylogenetic Tree of the sequences mentioned in" 45 Similar sequences"', fig.title='Figure 22_4: Phylogenetic Tree of the sequences mentioned in" 45 Similar sequences"'}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```

Other Quotes:

- Start
```{r, echo=FALSE, fig.cap='\'Figure 22_4: Phylogenetic\' Tree of the sequences mentioned in 45 Similar sequences', fig.title='\'Figure 22_4: Phylogenetic\' Tree of the sequences mentioned in 45 Similar sequences'}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```

- Middle
```{r, echo=FALSE, fig.cap='Figure 22_4: \'Phylogenetic Tree of the sequences mentioned\' in 45 Similar sequences', fig.title='Figure 22_4: \'Phylogenetic Tree of the sequences mentioned\' in 45 Similar sequences'}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```

- End
```{r, echo=FALSE, fig.cap='Figure 22_4: Phylogenetic Tree of the sequences mentioned\' in 45 Similar sequences\'', fig.title='Figure 22_4: Phylogenetic Tree of the sequences mentioned\' in 45 Similar sequences\''}
knitr::include_graphics("200 University/04/BE22 Bioinformatics/Task 7 Phylogenetic Tree/GuideTree (actual Phylotree).PNG")
```
obsidian.ahk
#Warn
#Requires Autohotkey v1.1.10+

converted := ConvertSRC_SYNTAX(A_ScriptDir "\ObsidianHTML-Output.md")
OutputDebug % converted
FileOpen(A_ScriptDir "\converted.md", 0x1).Write(converted)


return ; End of auto-execute


ConvertSRC_SYNTAX(PathOrContent) {
    if (FileExist(PathOrContent))
        FileRead buffer, % PathOrContent
    else
        buffer := PathOrContent
    p := 1
    ;@ahk-neko-ignore 1 line
    regex = <img src="(?<SRC>.+)"  width="(?<WIDTH>\d*)" alt="(?<ALT>.*)" title="(?<TITLE>.*)" \/>
    while (p := RegExMatch(buffer, "iOU)" regex, match, p)) {
        options := ""
        src := DecodeUriComponent(match.src)
        if (match.width)
            options .= "out.width='" match.width "', "
        if (match.alt)
            options .= "fig.cap='" Clean(match.alt) "', "
        if (match.title)
            options .= "fig.title='" Clean(match.title) "', "
        options := RTrim(options, ", ")
        tpl =
            (LTrim
            ``````{r, echo=FALSE, %options%}
            knitr::include_graphics("%src%")
            ``````
            )
        buffer := StrReplace(buffer, match[0], tpl)
        p += StrLen(tpl)
    }
    tpl =
        (LTrim
        ---
        ``````{r setup, include=FALSE}
        knitr::opts_chunk$set(echo = FALSE)
        ``````
        )
    buffer := RegexReplace(buffer, "\n---", "`n" tpl,,, 1)
    return buffer
}

Clean(sText) {
    sText := _Decode(sText, 1)
    sText := StrReplace(sText, "'", "\'")
    return sText
}

DecodeEntities(sText) {
    return _Decode(sText, 1)
}

DecodeUriComponent(sText) {
    return _Decode(sText, 2)
}

; nMode
; 1 = HTML entity decode
; 2 = decodeURIComponent
_Decode(sText, nMode) {
    static document := ""
    if (document = "") {
        document := ComObjCreate("HTMLFile")
        document.write("<meta http-equiv='X-UA-Compatible' content='IE=Edge'>")
    }
    switch (nMode) {
        case 1:
            document.write(sText)
            txt := document.documentElement.innerText
            document.close()
        case 2:
            txt := document.parentWindow.decodeURIComponent(sText)
        default:
            txt := "Unknown " A_ThisFunc "() mode."
    }
    return txt
}

@Gewerd-Strauss
Copy link

That seems to work flawlessly. I'm sure I will find some stupid way to break this that I didn't think of yet (I seem very good at this, sadly), but so far: Thank you very much for all the help once again.

(And now back to studying :P)

@Gewerd-Strauss
Copy link

Hey, random question:
I am looking into building a config-GUI in a not-stupid way. For reference,

I am now trying to get a GUI build to give said arguments if I want to. Initially, I am just doing it for word (as it's the output I need working the fastest), and did so hardcoded. Obviously, that's... a nightmare.
Obviously I am not looking at implementing all of them (just... no), but a couple are relevant. For Word f.e., that would be "reference_docx" and "number_sections".

So the structure would be something along the lines of

varName=Value
<two spaces>Type: bool/string/number
<two spaces>Default:Value
<two spaces>Range:Min-Max
<two spaces>Description:Description String
...
NextVar=FALSE
....

And then you could parse this block by block and generate the GUI from there. Stuff like Range would only be valid for types which actually contain it - a Range doesn't make much sense on a string or bool, after all.
However, I am not sure how I'd do so without making it a 700-line large editor à la rajat's IniSettingsEditor, and even that's not quite what I am looking for - it's too unwieldy for this task :P

@anonymous1184
Copy link
Author

A couple of years ago, when I was teaching my kid AHK, he wanted to do something similar for GTA mods (or some other game mods).

We used file hashing as an example: https://redd.it/m0kzdy

Then you'll find how to dynamically create a GUI, fully auto (no x/y coordinates for anything).

Perhaps that can be of help, you create an object with properties for each of the elements and then a loop will take care of everything. Rather than, you know... adding an awful lot of elements to a GUI and manually position them.

@Gewerd-Strauss
Copy link

So... had a bit of brainstorming, since I am too busy to do this anyways right now and don't plan to start on it before my exams are over anyways. The current idea would be the following - sorry if I am jumbling jargon, it has been a while since I had to think about classes at all :P


Create a template class for outputformat of.
of.Attribute

where of:=new of(output_format) initiates with defaults (sets of.Template, of.Toc...)

of.Init(Type) sets defaults for all attributes.

An attribute is defined as

Attribute:=[Control:="" ,Type:="" ,Default:="" ,String:=" , Value:=""]

Where f.e.
of.Init("word_document") sets the equivalent of

of.TOC:={"Checkbox",boolean,false,"Add TOC?"}
of.Template:={"DDL","String",Template_docx",fPopulateDDL(Source)",""}
of.NumSecs:=....

Chosen Attributes, their types,explanation strings and defaults can be read back from a csv, à la

document_type,TOC?,TOC_depth,Template?,....

It gets pretty wide admittedly. The alternative would be a pseudo-array à la

document_type
    Key:|Control|Type|Default|String|Value
    Key:|Control|Type|Default|String|Value
    Key:|Control|Type|Default|String|Value
    Key:|Control|Type|Default|String|Value


document_type
    Key:|Control|Type|Default|String|Value
    Key:|Control|Type|Default|String|Value
    Key:|Control|Type|Default|String|Value
    Key:|Control|Type|Default|String|Value
    
document_type
...

and from there you would do something like

gui, 1: submit ; get the chosen `output_type`

of:=new of(output_type)
;; → of.TOC:={Control:"Checkbox",Type:"bool",Default:false,String:"Do you want to add a TOC?",Value:"",
gui, 2: new ....
for Argument, Obj in of
    gui, 2: add, % Obj.Control, v%Argument% , % Obj.String
gui, 2: show 

Not sure if/how I'd implement shit like limits in there, or if I just post-userinput go

if of.toc_depth.value<oc.toc_depth.min 
    of.toc_depth.value:=oc.toc_depth_min
    ...
;; and on submit, when building the RScript-String, you'd do

BuildRScriptContent(Path,of,...)
{

    SubmitString:="rmarkdown::" %of% "("  ;; pretty sure this is illegal cuz I'd be trying to get the name of the object, so I guess another attribute must be added where of:=new("word_document") adds key of.Output_Format:="word_document"
    for attribute, value in of
    {
        if value="" ;; need to find a valid string to signify that an element is not assigned
            value:=of[attribute].Default
        if of[attribute].Type=String
            value:=Quote(of[attribute].Default)
        SubmitString.="`n" attribute " = " Value
    }
     ;; and on with BuildRScript we go   
}


Does that make any sense? I'm just theorising right now, not sure if I am completely off the hooks or not.

@Gewerd-Strauss
Copy link

Because I am not quite sure if I understood your example properly, this is how I understood the generality of it.

@Gewerd-Strauss
Copy link

Gewerd-Strauss commented Jan 24, 2023

Just made a first draft:
Gewerd-Strauss/ObsidianKnittr@b5eca38

DynamicArguments.ahk/.ini is what you need.
I feel like I can do it this way, but I can't help but feel like I am still overcomplicating it.... My encoding format is probably not the best terrible to make this easy, nor is it likely to be expandable without major modifications. I am inclined to say fuck it and put every value into an edit field to trust the user to sort it out, but by that logic I can just as well write the R-Script completely by scratch from hand as well - that's not really the point.

I am aware this is all kinds of jumbled, probably both over- and underengineered, but I both wanna experiment and... get it done in a sensible way, if that makes sense?
I also haven't figured out how I want to emulate a FileSelectDialogue for template-selection properly, but that's required as well - or you do it via a Listview that is created & populated if a File-Variable exists...

@Gewerd-Strauss
Copy link

Gewerd-Strauss commented Jan 25, 2023

Just made a first draft: Gewerd-Strauss/ObsidianScripts@b5eca38

DynamicArguments.ahk/.ini is what you need. I feel like I can do it this way, but I can't help but feel like I am still overcomplicating it.... My encoding format is probably not the best to make this easy, nor is it likely to be expandable without major modifications. I am inclined to say fuck it and put every value into an edit field to trust the user to sort it out, but by that logic I can just as well write the R-Script completely by scratch from hand as well - that's not really the point.

I am aware this is all kinds of jumbled, probably both over- and underengineered, but I both wanna experiment and... get it done in a sensible way, if that makes sense?

Second Third draft, sorted out hte fileselect shenanigans, still janky imo:
Gewerd-Strauss/ObsidianKnittr@de88407
Gewerd-Strauss/ObsidianKnittr@c22bbcb

(Yes I theoretically should move this all over to another branch that's not "main", but... yea no. too late, maybe I pick that habit up on my next project :P)

@Gewerd-Strauss
Copy link

Quick Ping, please check the reddit chat.

@Gewerd-Strauss
Copy link

Sorry to revive this thread. It occured today that I never tested for german Umlaute äöü in the src, which are not correctly converted apparently.

Assuming the test file

---
creation date: "2023-02-26 23:10"
modification date: "2023-02-26 23:11"
tags: programming/bug 
---

!{{Umlaute in images_SRC_Bug.png|This subtitle contains "äöü".}}

Will result in the following input via FileRead buffer, % PathOrContent:

---
creation date: 2023-02-26 23:10
modification date: 2023-02-26 23:11
tags:
- programming/bug
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```




```{r, echo=FALSE, fig.cap='This subtitle contains "äöü".', fig.title='This subtitle contains "äöü".'}
knitr::include_graphics("001 assets/Umlaute in images_SRC_Bug.png")
```

by the converter. This blocks umlaute from being part of image captions. This has never been discovered so far cuz 99.5% of my work is in english, and it never occured to me. The hotfix I employed is to modify the buffer-FileRead to

    Current_FileEncoding:=A_FileEncoding
    FileEncoding, UTF-8
    FileRead buffer, % PathOrContent
    FileEncoding, % Current_FileEncoding

Sidequestion: Why is A_FileEncoding empty if no encoding is specified explicitly?
The Docs don't suggest to me that it should be empty - unless I am completely misunderstanding something.


This initially surfaced while examining this janky hell, and is topically related.

This makes sense so far, and the above fix seems to resolve that part of the greater issue.

However, the wild goose chase I am on due to the issue I outlined in the reddit post above is still ongoing, and I am not sure how to resolve it :P
And I could not figure out how I'd resolve it properly - aside from banning umlaute in filenames, I guess. But that obviously should not be the actual solution.

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