8/4/26 21:23

This commit is contained in:
Eric Christensen
2026-08-04 21:23:11 -07:00
parent cfb3f16f82
commit caba177285
14 changed files with 353 additions and 25 deletions
View File
+2
View File
@@ -12,4 +12,6 @@ switch ($Command) {
"debug" { odin build $src -out:$out -debug } "debug" { odin build $src -out:$out -debug }
"test" { odin test .\tests\ -all-packages } "test" { odin test .\tests\ -all-packages }
"clean" { Remove-Item -Recurse -Force bin -ErrorAction SilentlyContinue } "clean" { Remove-Item -Recurse -Force bin -ErrorAction SilentlyContinue }
"golib" { go build -buildmode=c-shared -o libgoldmark.dll parser.go }
"libc" { lib /def:libgoldmark.def /out:libgoldmark.lib /machine:x64 }
} }
+12
View File
@@ -0,0 +1,12 @@
module pheynnx
go 1.26.5
require github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc
require (
github.com/alecthomas/chroma/v2 v2.27.0 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/dlclark/regexp2/v2 v2.2.1 // indirect
github.com/yuin/goldmark v1.4.15 // indirect
)
+27
View File
@@ -0,0 +1,27 @@
github.com/alecthomas/chroma/v2 v2.2.0 h1:Aten8jfQwUqEdadVFFjNyjx7HTexhKP0XuqBG67mRDY=
github.com/alecthomas/chroma/v2 v2.2.0/go.mod h1:vf4zrexSH54oEjJ7EdB65tGNHmH3pGZmVkgTP5RHvAs=
github.com/alecthomas/chroma/v2 v2.27.0 h1:FodwmyOBgJULFYmDqibcp9pvfDLWdtPRh9v/r5BXYZs=
github.com/alecthomas/chroma/v2 v2.27.0/go.mod h1:NjJ3ciIgrqBNeIkWZ4e46nseoLDslxU1LmfCoL+wcY8=
github.com/alecthomas/chroma/v3 v3.0.0-alpha.5 h1:Ins5lDliEp34swfd+nh2eESjBA4MlrHrmi6Uyxsl/9E=
github.com/alecthomas/chroma/v3 v3.0.0-alpha.5/go.mod h1:CjTPYmVdv0LiMgid2gCJeE30AgchDKbdsW7R3xs9mHI=
github.com/alecthomas/repr v0.0.0-20220113201626-b1b626ac65ae/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/dlclark/regexp2 v1.7.0 h1:7lJfhqlPssTb1WQx4yvTHN0uElPEv52sbaECrAQxjAo=
github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/dlclark/regexp2/v2 v2.2.1 h1:mf4KkFUj0gJuarK8P+LgiS+Lit7m9N1yAwEfPbee7R0=
github.com/dlclark/regexp2/v2 v2.2.1/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU=
github.com/dlclark/regexp2/v2 v2.2.2 h1:MYWvNYw8okuqNhwTYO587EZMiDruVa2vhV6fsGpfya0=
github.com/dlclark/regexp2/v2 v2.2.2/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yuin/goldmark v1.4.15 h1:CFa84T0goNn/UIXYS+dmjjVxMyTAvpOmzld40N/nfK0=
github.com/yuin/goldmark v1.4.15/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yuin/goldmark v1.8.5 h1:r6N5afV5qj/5S4UTch8agZHJ8UxNCMwX7WjkkJam2NA=
github.com/yuin/goldmark v1.8.5/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc h1:+IAOyRda+RLrxa1WC7umKOZRsGq4QrFFMYApOeHzQwQ=
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc/go.mod h1:ovIvrum6DQJA4QsJSovrkC4saKHQVs7TvcaeO8AIl5I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+4
View File
@@ -0,0 +1,4 @@
; libgoldmark.def
EXPORTS
MarkdownToHTML
FreeString
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+94
View File
@@ -0,0 +1,94 @@
/* Code generated by cmd/cgo; DO NOT EDIT. */
/* package command-line-arguments */
#line 1 "cgo-builtin-export-prolog"
#include <stddef.h>
#ifndef GO_CGO_EXPORT_PROLOGUE_H
#define GO_CGO_EXPORT_PROLOGUE_H
#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
extern size_t _GoStringLen(_GoString_ s);
extern const char *_GoStringPtr(_GoString_ s);
#endif
#endif
/* Start of preamble from import "C" comments. */
#line 3 "parser.go"
#include <stdlib.h>
#line 1 "cgo-generated-wrapper"
/* End of preamble from import "C" comments. */
/* Start of boilerplate cgo prologue. */
#line 1 "cgo-gcc-export-header-prolog"
#ifndef GO_CGO_PROLOGUE_H
#define GO_CGO_PROLOGUE_H
typedef signed char GoInt8;
typedef unsigned char GoUint8;
typedef short GoInt16;
typedef unsigned short GoUint16;
typedef int GoInt32;
typedef unsigned int GoUint32;
typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef GoUint64 GoUint;
typedef size_t GoUintptr;
typedef float GoFloat32;
typedef double GoFloat64;
#ifdef _MSC_VER
#if !defined(__cplusplus) || _MSVC_LANG <= 201402L
#include <complex.h>
typedef _Fcomplex GoComplex64;
typedef _Dcomplex GoComplex128;
#else
#include <complex>
typedef std::complex<float> GoComplex64;
typedef std::complex<double> GoComplex128;
#endif
#else
typedef float _Complex GoComplex64;
typedef double _Complex GoComplex128;
#endif
/*
static assertion to make sure the file is being used on architecture
at least with matching size of GoInt.
*/
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef _GoString_ GoString;
#endif
typedef void *GoMap;
typedef void *GoChan;
typedef struct { void *t; void *v; } GoInterface;
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
#endif
/* End of boilerplate cgo prologue. */
#ifdef __cplusplus
extern "C" {
#endif
extern char* MarkdownToHTML(char* source);
extern void FreeString(char* s);
#ifdef __cplusplus
}
#endif
BIN
View File
Binary file not shown.
+59
View File
@@ -0,0 +1,59 @@
package main
// #include <stdlib.h>
import "C"
import (
"bytes"
"fmt"
"unsafe"
chromahtml "github.com/alecthomas/chroma/v2/formatters/html"
"github.com/yuin/goldmark"
highlighting "github.com/yuin/goldmark-highlighting/v2"
"github.com/yuin/goldmark/util"
)
var md = goldmark.New(
goldmark.WithExtensions(
highlighting.NewHighlighting(
highlighting.WithStyle("github-dark"),
highlighting.WithWrapperRenderer(func(w util.BufWriter, context highlighting.CodeBlockContext, entering bool) {
lang, _ := context.Language()
if entering {
if lang == nil {
w.WriteString(`<div><pre class="aero"><code>`)
return
}
w.WriteString(fmt.Sprintf(`<div class="code-block"><p class="code-block-header"><span class="language-name">%s</span></p><pre class="aero"><code>`, lang))
} else {
w.WriteString(`</code></pre></div>`)
}
}),
highlighting.WithFormatOptions(
chromahtml.PreventSurroundingPre(true),
),
),
),
)
//export MarkdownToHTML
func MarkdownToHTML(source *C.char) *C.char {
src := C.GoString(source)
var buf bytes.Buffer
if err := md.Convert([]byte(src), &buf); err != nil {
return C.CString("")
}
return C.CString(buf.String())
}
//export FreeString
func FreeString(s *C.char) {
C.free(unsafe.Pointer(s))
}
func main() {} // required, unused
+22
View File
@@ -8,9 +8,17 @@ import "core:path/filepath"
import "core:strings" import "core:strings"
import http "submodules/odin-http" import http "submodules/odin-http"
foreign import goldmark "libgoldmark.lib"
foreign goldmark {
MarkdownToHTML :: proc(source: cstring) -> cstring ---
FreeString :: proc(s: cstring) ---
}
State :: struct { State :: struct {
num: int, num: int,
global_css: string, global_css: string,
import_html: cstring,
} }
state := State { state := State {
@@ -18,6 +26,18 @@ state := State {
} }
main :: proc() { main :: proc() {
markdown, err1 := os.read_entire_file_from_path("test.markdown", context.temp_allocator)
src_c := strings.clone_to_cstring(string(markdown))
result_c := MarkdownToHTML(src_c)
defer FreeString(result_c)
defer delete(src_c)
state.import_html = result_c
context.logger = log.create_console_logger(.Info) context.logger = log.create_console_logger(.Info)
data, err2 := os.read_entire_file_from_path("styles/main.css", context.temp_allocator) data, err2 := os.read_entire_file_from_path("styles/main.css", context.temp_allocator)
@@ -56,6 +76,8 @@ main :: proc() {
err := http.listen_and_serve(&s, routed, net.Endpoint{address = net.IP4_Loopback, port = 6969}) err := http.listen_and_serve(&s, routed, net.Endpoint{address = net.IP4_Loopback, port = 6969})
fmt.assertf(err == nil, "server stopped with error: %v", err) fmt.assertf(err == nil, "server stopped with error: %v", err)
free_all(context.temp_allocator)
} }
// ROUTERS // ROUTERS
+1 -23
View File
File diff suppressed because one or more lines are too long
+129
View File
@@ -0,0 +1,129 @@
---
title: String Interpolation
published: true
featured: true
author: eac
date: "Oct 25, 2024"
snippet: "String interpolation embeds variables directly in strings for dynamic, readable text. For example, Python's f-strings use {} to include variables or expressions seamlessly, simplifying output formatting."
categories:
- python
- premium
- print "Hello World"
- blizzard
- silver
- attention
skills:
- svelte
- typescript
- javascript
- nim
- rust
- golang
- github-actions
- bash
- apple
---
# Header
## Headers
### Headerss
```svelte
<script>
import Link from '#/Link.svelte';
</script>
<nav>
<link href="/" title="Home" />
<link href="/blog" title="Blog" />
<link href="/projects" title="Projects" />
<link href="/about-me" title="About Me" />
</nav>
```
```typescript
const materials = ["Hydrogen", "Helium", "Lithium", "Beryllium"];
console.log(materials.map((material) => material.length));
// Expected output: Array [8, 6, 7, 9]
(function (a) {
return a + 100;
});
const a = async (x) => {
return x++;
};
```
```nim
import macros, strutils
macro toLookupTable(data: static[string]): untyped =
result = newTree(nnkBracket)
for w in data.split(';'):
result.add newLit(w)
const
data = "mov;btc;cli;xor"
opcodes = toLookupTable(data)
for o in opcodes:
echo o
```
```java
BufferedWriter out = null;
try {
out = new BufferedWriter(new FileWriter("filename", true));
out.write("aString");
} catch (IOException e) {
// error processing code
} finally {
if (out != null) {
out.close();
}
}
```
```scss
$font-stack: Helvetica, sans-serif;
$primary-color: #333;
body {
font: 100% $font-stack;
color: $primary-color;
}
```
```rust
fn main() {
let user = ("Adrian", 38);
println!("User {} is {} years old", user.0, user.1);
// tuples within tuples
let employee = (("Adrian", 38), "die Mobiliar");
println!("User {} is {} years old and works for {}", employee.0.1, employee.0.1, employee.1);
}
```
```go
func Example() {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("hello world"))
}))
defer ts.Close()
resp, err := http.Get(ts.URL)
if err != nil {
fmt.Println(err)
}
defer resp.Body.Close()
fmt.Printf("%s\n", resp.Status)
fmt.Printf("%d\n", resp.StatusCode)
}
```
+1
View File
@@ -20,6 +20,7 @@ render_index_page :: proc(s: ^State) -> string {
<main id="content"> <main id="content">
<h1>Hello!</h1>`) <h1>Hello!</h1>`)
fmt.sbprintf(&b, `<h2>%v</h2>`, state.num) fmt.sbprintf(&b, `<h2>%v</h2>`, state.num)
fmt.sbprintf(&b, `<div>%v</div>`, state.import_html)
strings.write_string(&b, `</main></body></html>`) strings.write_string(&b, `</main></body></html>`)
return strings.clone(strings.to_string(b)) return strings.clone(strings.to_string(b))