Skip to content

JDN89/h2m

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

h2m

Hobby project to learn golang. The goals is convert the blog What color is your function from html to markdown. Maybe I'll generalize it, so it works with all sorts of blogs.

TODO

  • I haven't used interfaces at all and don't remember how they work in go. Are they similar to java interfaces? look into it and see if i have a usecase for them here.
  • output markdown
  • create todos based on my comment of 21/08/2025
  • If I want to be able to get rid of the bloat inside html tags. I must store the beginning of the tag but also of the content. Or mayby I don't need to store the conent, and storing the start and endo of the tags is just enough, and I just replace the complete tag with the equivalent markdown content.
  • after parsing the header start generating markdown based on the token stream
  • checkout Go release 1.25 and the note about faster slices, other article,dreams of code video

optimize

  • use channels : see one of my notes
  • use trie in lexer (see todo)

References

What is an idiomatic way of representing enums in Go?
Learning Go, and the type keyword is incredibly powerful and makes code more readable
moving from classes to golang
labeld loops mutable-strings-in-golang
strings-in-golang
stack-overflow-how-to-check-value-in-map-go
strings package of go
TRIE in crafting interpretres chapter 16
type keyword in go
go by example slices
Arrays, slices (and strings): The mechanics of 'append'
Go slices : usage and internals
regex is fun
How to remove redundant spaces/whitespace from a string in Golang? \

Type definitions (not type aliases) zijn heel krachtig. Kan je bijvoorbeeld van een int een type maken specifiek voor je domein. Je type erft geen methods van het bovenliggen type en je kan je eigen methodes voor dat type specifieren. Verder kan je niet impliciet van int naar je type converten. Je moet expliciet casten. Verder type system info opzoeken en mee experimenteren. Waarschijnlijk ook meer lightweight dan maken van een class in Java. Per file kan je meerdere types definieren.

DONE

  • converter test outputs UNKNOWN token?
  • read about type keyword, slices and arrays in go. Because I forgot the details of the go reference I read before. allready added the references.
  • use trie like data structure in lexer (see todo)
  • fix anchor tag token not recognized -> dummy it's not in convertTokenToString
  • Get the content out of the h1 tag
  • anchor token, content token, anchor closing token. is enough to lex an anchor tag
  • recognized bug, document and use go strings HasPrefix package
  • rename peekCurrent, currPos, peekNext(). naming is confusing
  • fix makeContentTokenTest. After making htmlToken the '>' doesn't get consumed and is still in l.char. Consume last char after making the token sounds better, so the nextToken is properly set for the next run! breakpoint in consumeTag()
  • default option in lexer should not be readChar(), but should be makeContentToken().
  • fix bug lexing:<article><header> content </header> </article>
  • fix bug parsing <article> content </article> -- endless loop
  • install an LSP for markdown. I'm getting randomg error messaged in README.md... (nvim releated)
  • finish parsing first html element correctly
  • rename vars in lexer_test.go. atm confusing naming

CANCELLED TASKS

  • rip out l.char and just use currPos() and just use currPos. See log 08/09/2025.
  • fix regressionTest

Steps

  • Get html content
  • setup lexer
  • define html tags to scan (tokens)

Mapping html to markdown

| HTML Tag | Markdown Equivalent | | -------------------------- | -------------------- | ------- | | <h1> | # | | <h2> | ## | | <h3> | ### | | <h4> | #### | | <h5> | ##### | | <h6> | ###### | | <p> | (blank line) | | <br> | or \ | | <strong>, <b> | ** or __ | | <em>, <i> | * or _ | | <u> | (none) | | <del>, <s>, <strike> | ~~ | | <a> | []() | | <img> | ![]() | | <ul> | - or * | | <ol> | 1. | | <li> | -, *, or 1. | | <code> | ` | | <pre><code> | ``` | | <pre> | (indented or fenced) | | <blockquote> | > | | <hr> | --- or *** | | <table> | | | | <tr> | | | | <th> | |+--- | | <td> | | | | <div>, <span> | (none) | | <iframe>, <script> | (none) |

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages