Skip to content

Treewide: Convert Hugo callouts to GFM alerts#1269

Merged
fufexan merged 4 commits intohyprwm:mainfrom
Bugg4:gfm-alerts
Nov 1, 2025
Merged

Treewide: Convert Hugo callouts to GFM alerts#1269
fufexan merged 4 commits intohyprwm:mainfrom
Bugg4:gfm-alerts

Conversation

@Bugg4
Copy link
Contributor

@Bugg4 Bugg4 commented Oct 29, 2025

This converts all the Hugo style callouts to GFM alerts.
For example, this

{{< callout type=info >}}

To get the correct name for an `unmodified_key`, refer to [the section on uncommon syms](#uncommon-syms--binding-with-a-keycode)

{{< /callout >}}

gets converted to:

> [!NOTE]
> To get the correct name for an `unmodified_key`, refer to [the section on uncommon syms](#uncommon-syms--binding-with-a-keycode)

This is related to #1198 and it's meant make the codebase easier to lint by using standard markdown where possible, reducing Hugo specific markup to a minimum.

Some notes on the automated conversion that has been performed:

  • Callouts of type warning, important and info got converted to [!WARNING], [!IMPORTANT] and [!NOTE] respectively.
  • All callouts that did not have a type got converted to [!WARNING] by default, since they were highlighted in orange by Hugo. This will maintain visual continuity.
  • Blank lines after the opening markup ({{< callout type=warning >}}) and before the closing markup ({{</ callout >}}) were trimmed.
  • Blank lines mid-content were kept
  • See Meta: Introduce linting tools #1198 (comment) for a visual example of how they render before and after.

I'll include the script that I used here for documenation's sake, but let me know if I should push it to the repo:

(Can just be run from the repo's root, without args)

hugo-callouts-to-gfm-alerts.pl

#!/usr/bin/env perl
use strict;
use warnings;
use File::Find;

# Mapping from hugo callout type -> GFM alert type
my %map = (
    info      => 'NOTE',
    warning   => 'WARNING',
    important => 'IMPORTANT',
);

sub transform {
    my ($text) = @_;

    $text =~ s{
        \{\{<\s*callout(?:\s+type=(\w+))?\s*>\}\}   # opening shortcode
        (.*?)                                       # body
        \{\{<\s*/?\s*callout\s*>\}\}                # closing shortcode (forgiving of malformed closing tags)
    }{
        my $type = $1 // 'warning';
        my %map  = (info=>'NOTE', warning=>'WARNING', important=>'IMPORTANT');
        my $hdr  = $map{lc $type} // uc($type);
        my $body = $2;

        # Trim leading/trailing newlines inside the callout
        $body =~ s/^\n+//;
        $body =~ s/\n+$//;

        # If the very first line is empty, drop it
        $body =~ s/^\s*\n//;

        # Prefix all lines (including blanks) with "> "
        $body =~ s/^/> /mg;

        "> [!$hdr]\n$body"
    }egsx;

    return $text;
}


sub process_file {
    my ($file) = @_;
    return unless $file =~ /\.md$/i;

    local $/ = undef;
    open my $fh, '<', $file or die "Cannot open $file: $!";
    my $content = <$fh>;
    close $fh;

    my $new = transform($content);

    if ($new ne $content) {
        open my $out, '>', $file or die "Cannot write $file: $!";
        print $out $new;
        close $out;
        print "Transformed: $file\n";
    }
}

my $root = shift @ARGV // 'content';
find(
    {
        wanted   => sub { process_file($File::Find::name) if -f },
        no_chdir => 1,
    },
    $root
);

If this is merged, we may want to consider adding a note about the new alert style to the Contributing to the WIki section the README, to inform contributors about the change. Let me know if you want it mentioned and I'll add it.

Marked as draft as I skimmed about 20-25 pages opening them at random to check alerts looked correct, but did not confirm each and every conversion went well, aside from looking at the diff.
An additional pair of eyes is welcomed :)
I'll give a more thorough look to all pages if we decide to go forward with this ✌️

Copy link
Member

@fufexan fufexan left a comment

Choose a reason for hiding this comment

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

one miss, rest lgtm.

This was missed because the type was enclosed in quotes
@Bugg4 Bugg4 marked this pull request as ready for review October 30, 2025 18:46
@Bugg4 Bugg4 marked this pull request as draft October 30, 2025 18:53
@Bugg4
Copy link
Contributor Author

Bugg4 commented Oct 30, 2025

Ok, will mark as ready for merge once I skimmed all the pages

@Bugg4 Bugg4 marked this pull request as ready for review October 30, 2025 19:20
- Alerts that contained a heading have been changed so that the "heading" now appears in place of the alert title. The alert icon and color still reflect the alert type.
- Removed unneccessary blank space.
@Bugg4
Copy link
Contributor Author

Bugg4 commented Oct 30, 2025

Ready for merge

@Bugg4 Bugg4 requested a review from fufexan November 1, 2025 12:48
Copy link
Member

@fufexan fufexan left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM

@fufexan fufexan merged commit a9624be into hyprwm:main Nov 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants