mirror of
https://github.com/SigNoz/signoz.git
synced 2026-08-10 15:00:47 +01:00
refactor(markdownrenderer): drop unused Jira ADF whole-doc helpers
Remove RenderJiraADF and adf.Doc: the Jira notifier builds the issue description itself (status panel + adf.Render body + deep-links) and never used the whole-document wrappers. Point the adf tests at adf.Render.
This commit is contained in:
@@ -18,16 +18,6 @@ import (
|
||||
// fragments plain text into word tokens while scanning for bare URLs.
|
||||
var parser = goldmark.New(goldmark.WithExtensions(extension.Strikethrough)).Parser()
|
||||
|
||||
// Doc renders markdown into a complete ADF document. An empty input yields a
|
||||
// document with a single empty paragraph, since ADF requires non-empty content.
|
||||
func Doc(markdown string) map[string]any {
|
||||
content := Render(markdown)
|
||||
if len(content) == 0 {
|
||||
content = []any{map[string]any{"type": "paragraph"}}
|
||||
}
|
||||
return map[string]any{"type": "doc", "version": 1, "content": content}
|
||||
}
|
||||
|
||||
// Render returns the ADF block nodes for markdown (without the doc wrapper),
|
||||
// so callers can embed them alongside their own nodes (panels, links, …).
|
||||
func Render(markdown string) []any {
|
||||
|
||||
@@ -16,7 +16,7 @@ func toJSON(t *testing.T, v any) string {
|
||||
}
|
||||
|
||||
func TestRenderInlineMarks(t *testing.T) {
|
||||
js := toJSON(t, Doc("**bold** and *em* and `code` and [txt](https://x.io)"))
|
||||
js := toJSON(t, Render("**bold** and *em* and `code` and [txt](https://x.io)"))
|
||||
assert.Contains(t, js, `"type":"strong"`)
|
||||
assert.Contains(t, js, `"type":"em"`)
|
||||
assert.Contains(t, js, `"type":"code"`)
|
||||
@@ -26,7 +26,7 @@ func TestRenderInlineMarks(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRenderHeadingAndList(t *testing.T) {
|
||||
js := toJSON(t, Doc("# Title\n\n- a\n- b"))
|
||||
js := toJSON(t, Render("# Title\n\n- a\n- b"))
|
||||
assert.Contains(t, js, `"type":"heading"`)
|
||||
assert.Contains(t, js, `"level":1`)
|
||||
assert.Contains(t, js, `"type":"bulletList"`)
|
||||
@@ -34,27 +34,23 @@ func TestRenderHeadingAndList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRenderOrderedList(t *testing.T) {
|
||||
js := toJSON(t, Doc("1. one\n2. two"))
|
||||
js := toJSON(t, Render("1. one\n2. two"))
|
||||
assert.Contains(t, js, `"type":"orderedList"`)
|
||||
}
|
||||
|
||||
func TestRenderCodeBlock(t *testing.T) {
|
||||
js := toJSON(t, Doc("```go\nx := 1\n```"))
|
||||
js := toJSON(t, Render("```go\nx := 1\n```"))
|
||||
assert.Contains(t, js, `"type":"codeBlock"`)
|
||||
assert.Contains(t, js, `"language":"go"`)
|
||||
assert.Contains(t, js, `x := 1`)
|
||||
}
|
||||
|
||||
func TestRenderPlainText(t *testing.T) {
|
||||
js := toJSON(t, Doc("just text"))
|
||||
js := toJSON(t, Render("just text"))
|
||||
assert.Contains(t, js, `"type":"paragraph"`)
|
||||
assert.Contains(t, js, `"text":"just text"`)
|
||||
}
|
||||
|
||||
func TestRenderEmptyIsValidDoc(t *testing.T) {
|
||||
d := Doc("")
|
||||
content, ok := d["content"].([]any)
|
||||
require.True(t, ok)
|
||||
require.Len(t, content, 1)
|
||||
assert.Equal(t, "paragraph", content[0].(map[string]any)["type"])
|
||||
func TestRenderEmptyIsEmpty(t *testing.T) {
|
||||
assert.Empty(t, Render(""))
|
||||
}
|
||||
|
||||
@@ -2,11 +2,9 @@ package markdownrenderer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"sync"
|
||||
|
||||
"github.com/SigNoz/signoz/pkg/errors"
|
||||
"github.com/SigNoz/signoz/pkg/templating/markdownrenderer/adf"
|
||||
"github.com/SigNoz/signoz/pkg/templating/markdownrenderer/blockkit"
|
||||
"github.com/SigNoz/signoz/pkg/templating/markdownrenderer/mrkdwn"
|
||||
"github.com/yuin/goldmark"
|
||||
@@ -55,15 +53,6 @@ func RenderSlackMrkdwn(markdown string) (string, error) {
|
||||
return render(md, markdown, "Slack mrkdwn")
|
||||
}
|
||||
|
||||
// RenderJiraADF converts markdown to a Jira Atlassian Document Format JSON document.
|
||||
func RenderJiraADF(markdown string) (string, error) {
|
||||
b, err := json.Marshal(adf.Doc(markdown))
|
||||
if err != nil {
|
||||
return "", errors.WrapInternalf(err, errors.CodeInternal, "failed to convert markdown to Jira ADF")
|
||||
}
|
||||
return string(b), nil
|
||||
}
|
||||
|
||||
func render(md goldmark.Markdown, markdown string, format string) (string, error) {
|
||||
var buf bytes.Buffer
|
||||
if err := md.Convert([]byte(markdown), &buf); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user