-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Support asciicast files as new markup #22448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
b795c6c
feat: add markup asciicast
wolfogre 9f81e08
chore: install asciinema-player
wolfogre c7b31a1
feat: init asciinema-player
wolfogre a76bfed
fix: import css
wolfogre 9530aae
feat: extractHeader
wolfogre 1c613dc
Revert "feat: extractHeader"
wolfogre ca060fc
fix: style
wolfogre a35e1b5
Merge branch 'main' into feature/asciicast
wolfogre 7aa33b5
Merge branch 'main' into feature/asciicast
wolfogre 3599acc
Merge branch 'main' into feature/asciicast
wolfogre 662aad5
chore: move files
wolfogre 87f8502
fix: await import
wolfogre b27835a
Merge branch 'main' into feature/asciicast
wolfogre aacb4ca
fix: typo
wolfogre 4ecd738
chore: comments for poster
wolfogre 6a7b580
Merge branch 'main' into feature/asciicast
wolfogre 22399ec
Update web_src/js/markup/asciinema.js
wolfogre 4869640
chore: rename to asciicast.js
wolfogre f849825
Merge branch 'main' into feature/asciicast
wolfogre b0a17f6
chore: reinstall asciinema-player
wolfogre cbb0fb5
Merge branch 'main' into feature/asciicast
lunny c63a167
Merge branch 'main' into feature/asciicast
lunny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package asciicast | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/url" | ||
"regexp" | ||
|
||
"code.gitea.io/gitea/modules/markup" | ||
"code.gitea.io/gitea/modules/setting" | ||
) | ||
|
||
func init() { | ||
markup.RegisterRenderer(Renderer{}) | ||
} | ||
|
||
// Renderer implements markup.Renderer for asciicast files. | ||
// See https://github.com/asciinema/asciinema/blob/develop/doc/asciicast-v2.md | ||
type Renderer struct{} | ||
|
||
// Name implements markup.Renderer | ||
func (Renderer) Name() string { | ||
return "asciicast" | ||
} | ||
|
||
// Extensions implements markup.Renderer | ||
func (Renderer) Extensions() []string { | ||
return []string{".cast"} | ||
} | ||
|
||
const ( | ||
playerClassName = "asciinema-player-container" | ||
playerSrcAttr = "data-asciinema-player-src" | ||
) | ||
|
||
// SanitizerRules implements markup.Renderer | ||
func (Renderer) SanitizerRules() []setting.MarkupSanitizerRule { | ||
return []setting.MarkupSanitizerRule{ | ||
{Element: "div", AllowAttr: "class", Regexp: regexp.MustCompile(playerClassName)}, | ||
{Element: "div", AllowAttr: playerSrcAttr}, | ||
} | ||
} | ||
|
||
// Render implements markup.Renderer | ||
func (Renderer) Render(ctx *markup.RenderContext, _ io.Reader, output io.Writer) error { | ||
rawURL := fmt.Sprintf("%s/%s/%s/raw/%s/%s", | ||
setting.AppSubURL, | ||
url.PathEscape(ctx.Metas["user"]), | ||
url.PathEscape(ctx.Metas["repo"]), | ||
ctx.Metas["BranchNameSubURL"], | ||
url.PathEscape(ctx.RelativePath), | ||
) | ||
|
||
_, err := io.WriteString(output, fmt.Sprintf( | ||
`<div class="%s" %s="%s"></div>`, | ||
playerClassName, | ||
playerSrcAttr, | ||
rawURL, | ||
)) | ||
return err | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import * as AsciinemaPlayer from 'asciinema-player'; | ||
|
||
export function initAsciinemaPlayer() { | ||
const players = document.getElementsByClassName('asciinema-player-container'); | ||
for (const player of players) { | ||
AsciinemaPlayer.create(player.getAttribute('data-asciinema-player-src'), player, { | ||
poster: 'npt:1:0:0', | ||
}); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@import "asciinema-player/dist/bundle/asciinema-player.css"; | ||
|
||
.asciinema-player-container { | ||
width: 100%; | ||
height: auto; | ||
} | ||
|
||
.asciinema-terminal { | ||
overflow: hidden !important; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -470,6 +470,10 @@ | |
pre { | ||
overflow: auto; | ||
} | ||
|
||
.asciicast { | ||
padding: 5px !important; | ||
} | ||
} | ||
|
||
.sidebar { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,5 +36,6 @@ | |
@import "_explore"; | ||
@import "_review"; | ||
@import "_package"; | ||
@import "_asciicast"; | ||
|
||
@import "./helpers.less"; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.