Skip to content

Commit

Permalink
embedghlivesample
Browse files Browse the repository at this point in the history
  • Loading branch information
viperehonchuk committed Jan 10, 2024
1 parent 3df0e35 commit 890b01c
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion hashes.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions revamp/postprocessors/src/populate-algolia/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"github.com/PuerkitoBio/goquery"
)

var NO_GO_TAGS []string = []string{"#formalnyi-syntaksys", "#spetsyfikatsii", "script", "style", "noscript", "table", "pre", "ul", "ol", "h1", "blockquote", ".notecard", ".bc-data"}
var NO_GO_TAGS []string = []string{"#formalnyi-syntaksys", "#spetsyfikatsii", "script", "style", "noscript", "table", "pre", "ul", "ol", "h1", "blockquote", ".notecard", ".bc-data", ".bc-specs", "iframe"}

var CUT_MARKERS []string = []string{"#dyvitsia-takozh", "#avtory-statti", "#avtory-perekladu"}
var CUT_MARKERS []string = []string{"#dyvitsia-takozh", "#avtory-statti", "#avtory-perekladu", "#sumisnist-iz-brauzeramy"}

// Removes all html tags from the given html string
func extractTextFromHtml(htmlCode []byte) (string, string, error) {
Expand Down
5 changes: 5 additions & 0 deletions revamp/postprocessors/src/revamp-html/fix-code-links.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"html"
"strings"

"github.com/PuerkitoBio/goquery"
Expand All @@ -13,6 +14,10 @@ func fixCodeLinks(doc *goquery.Document) error {
if strings.Contains(text, "<") {
selection.SetHtml(text)
// log.Printf("text after: %s", selection.Text())
title, titleExists := selection.Attr("title")
if titleExists {
selection.SetAttr("title", html.UnescapeString(title))
}
}
})
return nil
Expand Down
1 change: 1 addition & 0 deletions revamp/preprocessors/src/helpers/render_html/iframe.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type IframeParams struct {
Height template.HTMLAttr
Src template.HTMLAttr
Title template.HTMLAttr
Width template.HTMLAttr
}

func RenderIframe(params *IframeParams) (string, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ class="{{.Class}}"
height="{{.Height}}"
src="{{.Src}}"
title="{{.Title}}"
width="{{.Width}}"
></iframe>
44 changes: 44 additions & 0 deletions revamp/preprocessors/src/run-macros/macros/embedghlivesample.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package macros

import (
"errors"
"html/template"
"strings"
preprocessor_helpers "webdoky3/revamp/preprocessors/src/helpers"
renderhtml "webdoky3/revamp/preprocessors/src/helpers/render_html"
"webdoky3/revamp/preprocessors/src/run-macros/environment"
"webdoky3/revamp/preprocessors/src/run-macros/registry"
)

func parseEmbedghlivesampleArgs(args string) (string, string, string, error) {
// args: "path,width,height"
// Split the args string into a slice of strings
// using the comma as the separator
// (e.g., "path,width,height" -> ["path", "width", "height"])
argSlice := strings.Split(args, ",")
switch len(argSlice) {
case 0:
return "", "", "", errors.New("no arguments")
case 1:
return preprocessor_helpers.UnwrapString(argSlice[0]), "", "", nil
case 2:
return preprocessor_helpers.UnwrapString(argSlice[0]), preprocessor_helpers.UnwrapString(argSlice[1]), "", nil
case 3:
return preprocessor_helpers.UnwrapString(argSlice[0]), preprocessor_helpers.UnwrapString(argSlice[1]), preprocessor_helpers.UnwrapString(argSlice[2]), nil
default:
return "", "", "", errors.New("too many arguments")
}
}

func embedghlivesample(env *environment.Environment, _ *registry.Registry, args string) (string, error) {
path, width, height, err := parseEmbedghlivesampleArgs(args)
if err != nil {
return "", err
}
return renderhtml.RenderIframe(&renderhtml.IframeParams{
Height: template.HTMLAttr(height),
Src: template.HTMLAttr("https://webdoky.github.io/" + path),
Width: template.HTMLAttr(width),
})

}
1 change: 1 addition & 0 deletions revamp/preprocessors/src/run-macros/macros/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var MacrosIndex = map[string]func(*environment.Environment, *registry.Registry,
"cssxref": cssxref.Cssxref,
"deprecated_header": deprecated_header,
"domxref": domxref,
"embedghlivesample": embedghlivesample,
"embedinteractiveexample": embedinteractiveexample,
"embedlivesample": embedlivesample.Embedlivesample,
"glossary": glossary,
Expand Down

0 comments on commit 890b01c

Please sign in to comment.