Skip to content

feat(gnoweb): readme markdown viewer for p/ & r/ #4101

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

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

alexiscolin
Copy link
Member

@alexiscolin alexiscolin commented Apr 10, 2025

⚠️ WIP — Fixes: #4070

This PR implements a new feature to display README.md files in a formatted way for both pures (p/) and realms (r/) in gno.land. This would apply in Directory template and in Source template.

Changes

  • Added a new RenderMd method to HTMLWebClient that:

    • Takes a path and filename as input
    • Reads the markdown file using SourceFile
    • Parses and renders the markdown content using the existing ParseMarkdown function
    • Generates a table of contents for the markdown content (WIP)
    • Returns the rendered content and metadata
  • Modified the GetDirectoryView handler to:

    • Check for the presence of README.md in the directory
    • If found, render it using the new RenderMd method
    • Display the rendered README content at the top of the directory listing
    • Move README.md to the first position in the file list
  • Reuse code to create a new generateTOC helper method to HTMLWebClient that:

    • Takes a parsed markdown document and its content
    • Generates a table of contents with configurable depth (2-6 levels - reuse RealmView settings)
  • In Source template, a markdown file is automatically rendered with Goldmark in HTML:

    • Automatically detect and render markdown files (.md) in preview mode
    • Add a toggle button to switch between markdown preview and code view
    • Support the plain WebQuery to force code view for markdown files

Benefits

  • Improves documentation visibility by automatically displaying README.md files
  • Maintains consistent markdown rendering across the platform
  • Avoid using the render function for md only content that could live in a simple md file
  • Provides navigation through table of contents for long README files
  • Integrates seamlessly with existing directory views

Technical Details

  • Uses the existing Goldmark markdown parser
  • Maintains the same styling and formatting as realm content
  • Preserves the ability to view raw source files

This feature enhances the user experience by making documentation more accessible and readable directly in the web interface.

TODO

  • Display md as html in source (add a switch button code <-> html)
  • Remove readme sorting (will be implemented)
  • Style and design
  • Tests

In Directory template

Capture d’écran 2025-04-10 à 15 08 51

In Source template

Capture d’écran 2025-04-10 à 17 45 03

@Gno2D2
Copy link
Collaborator

Gno2D2 commented Apr 10, 2025

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
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)
🟢 Changes related to gnoweb must be reviewed by its codeowners
🟢 Pending initial approval by a review team member, or review from tech-staff

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 The pull request was created from a fork (head branch repo: alexiscolin/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Changes related to gnoweb must be reviewed by its codeowners

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 A changed file matches this pattern: ^gno.land/pkg/gnoweb/ (filename: gno.land/pkg/gnoweb/app_test.go)

Then

🟢 Requirement satisfied
└── 🟢 Or
    ├── 🔴 This user reviewed pull request: alexiscolin
    └── 🟢 This user reviewed pull request: gfanton

Pending initial approval by a review team member, or review from tech-staff

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 Not (🔴 Pull request author is a member of the team: tech-staff)

Then

🟢 Requirement satisfied
└── 🟢 If
    ├── 🟢 Condition
    │   └── 🟢 Or
    │       ├── 🔴 At least 1 user(s) of the organization reviewed the pull request (with state "APPROVED")
    │       ├── 🟢 At least 1 user(s) of the team tech-staff reviewed pull request
    │       └── 🟢 This pull request is a draft
    └── 🟢 Then
        └── 🟢 Not (🔴 This label is applied to pull request: review/triage-pending)

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

@alexiscolin alexiscolin added the 🌍 gnoweb Issues & PRs related to gnoweb and render label Apr 10, 2025
Copy link

codecov bot commented Apr 10, 2025

Codecov Report

Attention: Patch coverage is 68.66667% with 47 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
gno.land/pkg/gnoweb/webclient_html.go 29.26% 25 Missing and 4 partials ⚠️
gno.land/pkg/gnoweb/handler.go 75.51% 9 Missing and 3 partials ⚠️
gno.land/pkg/gnoweb/webclient_mock.go 85.00% 4 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Member

@gfanton gfanton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First comment pass; I need to delve deeper for a full review, but I will wait for you to resolve the preliminary comments.

Comment on lines +41 to +45
markdown: goldmark.New(
goldmark.WithExtensions(
markdown.GnoExtension,
),
),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the mock cannot depend on goldmark

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test file doesn't make sense, you are not testing html client but the mock itself.
If no tests were existing before, it is because we need to have a mock for the RPC client itself to be able to test the HTML client.

Comment on lines +150 to +154
// If writer is nil, just return metadata
if w == nil {
return &fileMeta, nil
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writer cannot and should not be nil; remove this. it will complexity the caller logic

}

// RenderMd renders a markdown file and returns the rendered content
func (s *HTMLWebClient) RenderMd(w io.Writer, u *weburl.GnoURL, fileName string) (*RealmMeta, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func (s *HTMLWebClient) RenderMd(w io.Writer, u *weburl.GnoURL, fileName string) (*RealmMeta, error) {
func (s *HTMLWebClient) RenderMarkdownFile(w io.Writer, u *weburl.GnoURL, fileName string) (*RealmMeta, error) {

Comment on lines +9 to +14
type DisplayMode int

const (
ModeCode DisplayMode = iota
ModeMarkdown
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, if you are using this within the template, it makes no sense to use int here. Just change this to string, or find a way to expose this as const within the template. But if it's not something simple, simply use string.

Suggested change
type DisplayMode int
const (
ModeCode DisplayMode = iota
ModeMarkdown
)
type DisplayMode string
const (
ModeCode DisplayMode = "code"
ModeMarkdown = "markdown"
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌍 gnoweb Issues & PRs related to gnoweb and render 📦 ⛰️ gno.land Issues or PRs gno.land package related
Projects
Status: No status
Status: Triage
Development

Successfully merging this pull request may close these issues.

gnoweb: display README.md for p/ & r/
3 participants