Skip to content

Commit

Permalink
preprocessor: add ability to set language distinct from extension
Browse files Browse the repository at this point in the history
In code blocks, we currently use the extension of a file to set the
language of the code block. In some situations we need to vary this.
Specifically, because we do not yet have CUE syntax highlighting we need
to set the language for .cue files to be text, because setting the
language as cue breaks other features (like line numbers) in a rendered
code block.

The override to set the language for .cue files to "text" follows in a
later CL.

Signed-off-by: Paul Jolly <[email protected]>
Change-Id: I438d57e733e46adaef93c8ab5d84574c70262335
Preprocessor-No-Write-Cache: true
Dispatch-Trailer: {"type":"trybot","CL":1169624,"patchset":1,"ref":"refs/changes/24/1169624/1","targetBranch":"alpha"}
  • Loading branch information
myitcv authored and cueckoo committed Sep 19, 2023
1 parent 5ee07a5 commit 0ecd300
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions internal/cmd/preprocessor/cmd/sidebyside_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,18 @@ func (s *sidebysideNode) writeTransformTo(b *bytes.Buffer) error {
in, out := analyses[0], analyses[1]
tabs[0] = tabProps{
Name: strings.ToUpper(in.Ext),
Language: in.Ext,
Language: in.Language,
}
tabs[1] = tabProps{
Name: strings.ToUpper(out.Ext),
Language: out.Ext,
Language: out.Language,
Type: "terminal",
}
} else {
for i, a := range analyses {
tp := &tabs[i]
tp.Name = a.Filepath
tp.Language = a.Ext
tp.Language = a.Language
if a.IsOut {
tp.Name = "TERMINAL"
tp.Type = "terminal"
Expand Down
7 changes: 7 additions & 0 deletions internal/cmd/preprocessor/cmd/txtar_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ type filenameAnalysis struct {

// IsOut is set if the file is considered an output in the archive.
IsOut bool

// Language is the name used when rendering a code block for the
// archive file. In most cases this will be the same value as Ext
// but this field exists in order to allow for varying it.
Language string
}

// analyseTxtarArchive provides common analysis that is used by
Expand Down Expand Up @@ -221,6 +226,8 @@ func analyseFilename(p string) (res filenameAnalysis) {
// Found a .
res.Basename = b[:i]
res.Ext = b[i+1:]

res.Language = res.Ext
}
switch res.Basename {
case "out", "stdout":
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/preprocessor/cmd/upload_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (u *uploadNode) writeTransformTo(b *bytes.Buffer) error {
a := u.analysis.fileNames[0]
props := tabProps{
Name: f.Name,
Language: a.Ext,
Language: a.Language,
}
p("```%s { title=%q", props.Language, props.Name)

Expand Down

0 comments on commit 0ecd300

Please sign in to comment.