Skip to content

pumenis/source-highlight

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

source-highlight a go module

Golang module for highlighting sources that outputs html

Usage

package main

import (
	"embed"
	"fmt"
	"os"

	"github.com/pumenis/source-highlight/highlight"
)

//go:embed gosyntax.css
var goFile embed.FS

func main() {
	filePath := os.Args[1]

	content, err := os.ReadFile(filePath)
	if err != nil {
		fmt.Printf("Error reading file: %v", err)
		return
	}
	sourceCode := string(content)

	css, err := goFile.ReadFile("gosyntax.css")
	if err != nil {
		fmt.Printf("Error reading file: %v", err)
		return
	}

	result := highlight.GetGoHighlighted(sourceCode)
	fmt.Println(`<!DOCTYPE html>
	  <html><head>
	 	<style>` + string(css) + `</style>
		</head><div><pre>` + result + `</pre></div></html>`)
}
go run ./examples/highlight_go_file/ highlight/getGoHighlighted.go >/tmp/index.html

About

tree sitter source highlighter outputs html with highlighted source

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages