-
Notifications
You must be signed in to change notification settings - Fork 398
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
feat(gnoweb): Add gno-columns extension #3763
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: gfanton <[email protected]>
🛠 PR Checks SummaryAll Automated Checks passed. ✅ Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🟢 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
Signed-off-by: gfanton <[email protected]>
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
Let's go ❤️ |
Signed-off-by: gfanton <[email protected]>
Signed-off-by: gfanton <[email protected]>
Signed-off-by: gfanton <[email protected]>
Signed-off-by: gfanton <[email protected]>
@aeddi Yeah I agree regarding the readability but after some discussion in the dedicated issue, it seems people preferred the writing simplicity coupled with an opinionated gnoweb rendering based on headings (not images). To get the images, the hack is to create an empty heading. Please note that |
@alexiscolin Ok got it 👍 |
There is one last edge case that I’m unsure how to handle: <gno-columns>
content 1
content 2
## Title 1
content 3
## Title 2
content 4
</gno-columns> In this scenario, there is intermediary content between the opening tag and the first heading. Therefore, I suggest that we always create a first column, regardless of whether a heading is present. |
After some time to think about this, and considering that this edge case occurs because the first encountered title following the opening tag |
Signed-off-by: gfanton <[email protected]>
Signed-off-by: gfanton <[email protected]>
I have to check if the case "4 or more cols" can be rendered properly in one line with the current CSS. |
Signed-off-by: gfanton <[email protected]>
Signed-off-by: gfanton <[email protected]>
Signed-off-by: gfanton <[email protected]>
I've updated with option A in both scenarios. For In addition, I've updated our approach to handling golden tests by using the @aeddi @alexiscolin double-check txtar to see if the output format suits you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation seems good to me and I think the code generation is more coherent now. Can you just fix the few comments I left you and the lint errors, and then I think we'll be good. 👍
return false | ||
} | ||
|
||
fmt.Println(node.Kind()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover?
if len(line) == 0 { | ||
return ColumnTagUndefined | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check seems unnecessary given the rest of the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check has to be done at some point since we have to potentially check the first character of the line later in the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes, ok, just got the line 135.
WDYT about putting them together then so it's more clear? Like this:
if len(line) > 0 && line[0] == '#' {
return ColumnTagSep
}
(Or even using strings.HasPrefix
)
gno.land/pkg/gnoweb/markdown/golden/ext_column/invalid_scopping_columns.golden.txtar
Outdated
Show resolved
Hide resolved
IsClose, IsOpen bool | ||
Error error | ||
Index int | ||
RefHeadingLevel int // serves as a level reference for separators |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these fields exported? Leftover or Is it for encoding (or any similar operation)? Can you unexport them or add a comment about this?
if cctx.Error != nil { | ||
// Don't bother with malformed block | ||
return nil, parser.NoChildren | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check seems useless since getColumnContext
return a new context if cctx.Error != nil
.
For more clarity you could maybe just remove this getColumnContext
function and move its content here?
return ColumnTagUndefined | ||
} | ||
|
||
// Open opens a new column node based on the separator kind. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be me misunderstanding, but this comment seems unclear or even incorrect given the content of the function.
prev, ok := cnode.PreviousSibling().(*ColumnNode) | ||
if !ok || prev.Tag != ColumnTagOpen { | ||
fmt.Fprintln(w, "</div>") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you comment this part? I'm not sure to understand its purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's to avoid having to close a non-existing sep, but re reading this I think it should easier to just check index.
|
||
// columnContext struct and its methods are used for handling column context. | ||
type columnContext struct { | ||
IsClose, IsOpen bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reading the code related to these booleans, the fact that there are two doesn't seem necessary and is confusing.
Why not have a single boolean IsOpen
? (or IsClosed
if you want to init a new columnContext
with its false
value by default)?
Signed-off-by: gfanton <[email protected]>
Signed-off-by: gfanton <[email protected]>
Signed-off-by: gfanton <[email protected]>
Signed-off-by: gfanton <[email protected]>
Signed-off-by: gfanton <[email protected]>
Signed-off-by: gfanton <[email protected]>
…e content (#3909) once merged, we should take the habit of updating it when we extend gnoweb's rendering capabilities such as in #3763 --------- Signed-off-by: moul <[email protected]>
i moved the markdown_test realm into r/docs/markdown #3909 can you update this PR? |
content 2 | ||
</gno-columns> | ||
|
||
You can also use ` + "`:::`" + ` as a shortcut for creating columns: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's start with just <gno-columns>
.
:::
seems too 'precious' to be an alternative to something that's already concise and clear enough.
if ever we really want it, we can add it in another PR.
"github.com/yuin/goldmark" | ||
) | ||
|
||
type gno struct{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code is unclear; can you add a comment?
|
||
switch cnode.Tag { | ||
case ColumnTagOpen: | ||
fmt.Fprint(w, `<div class="gno-cols">`+"\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fmt.Fprint(w, `<div class="gno-cols">`+"\n") | |
fmt.Fprint(w, `<div class="gno-columns">`+"\n") |
to stay consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ext_columns.go
consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ext_columns
consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we avoid having those ".txtar" files that are really different from the other txtar files in the repo?
it looks more like a filetest.gno file in the spirit (one entrypoint, one output).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe ".mdtest"
RefHeadingLevel int // serves as a level reference for separators | ||
} | ||
|
||
func isPreviousNodeTag(node ast.Node, tag ColumnTag) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deadcode (and in general there are a lot of hard to read code) can you make a quick cleanup?
return ok && cnode.Tag == tag | ||
} | ||
|
||
// parseLineTag checks if the line starts with any of the tag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
incorrect, the code checks if the line is a tag, not if it starts with.
it actually doesn't support having a tag and something else on the right, which will be a need for upcoming extensions.
|
||
func (*columnParser) Close(_ ast.Node, reader text.Reader, _ parser.Context) {} | ||
|
||
func (*columnParser) CanInterruptParagraph() bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deadcode? if not add a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those methods are for block parsing interface; I will add an assert reference.
return true | ||
} | ||
|
||
func (*columnParser) CanAcceptIndentedLine() bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deadcode?
const testdataDir = "golden" | ||
|
||
var ( | ||
update = flag.Bool("update-golden-files", false, "update golden files") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update = flag.Bool("update-golden-files", false, "update golden files") | |
update = flag.Bool("update-golden-tests", false, "update golden files") |
for consistency
Addresses #3255
This PR implements column extension into
gnoweb
following this format:Notes
testdatas
files for example of input/output/r/demo/mardown_test
that need to be improved with usage, example and description (cc @leohhhn)Preview
example output code
example with images (empty heading)
TODO