summaryrefslogtreecommitdiff
path: root/web/cgit-extra.html
diff options
context:
space:
mode:
authoraura <nw@moneybot.cc>2026-02-17 01:48:02 +0100
committeraura <nw@moneybot.cc>2026-02-17 01:48:02 +0100
commit66114aff1fc110d39d279ef820144a051cd7fb04 (patch)
treee024c675190c222bb762ea10ea665dc408894ffa /web/cgit-extra.html
parent2f4b118cd28600216d40df776e0fead81a41d5cb (diff)
readme parse fix further
Diffstat (limited to 'web/cgit-extra.html')
-rw-r--r--web/cgit-extra.html68
1 files changed, 60 insertions, 8 deletions
diff --git a/web/cgit-extra.html b/web/cgit-extra.html
index 3b46fe7..927c912 100644
--- a/web/cgit-extra.html
+++ b/web/cgit-extra.html
@@ -76,10 +76,10 @@ function parseLink( text, start ) {
const close = text.indexOf( "]", open );
if( close === -1 ) return null;
- const lopen = text.indexOf( "(", close );
- if( lopen === -1 ) return null;
+ const lopen = close + 1;
+ if( text[lopen] != '(' ) return { continue: true, end: lopen };
const lclose = text.indexOf( ")", lopen );
- if( lclose === -1 ) return null;
+ if( lclose === -1 ) return { continue: true, end: lopen };
const title = text.substring( open + 1, close );
const link = text.substring( lopen + 1, lclose );
@@ -97,6 +97,11 @@ function parseLinks( text ) {
if( !res )
break;
+ if( res.continue ) {
+ start = res.end + 1;
+ continue;
+ }
+
links.push( res );
start = res.end + 1;
}
@@ -127,27 +132,73 @@ function replaceLinks( text, links ) {
return text;
}
+function escapeHtml( html ) {
+ const entityMap = {
+ '&': '&amp;',
+ '<': '&lt;',
+ '>': '&gt;',
+ '"': '&quot;',
+ "'": '&#39;',
+ '/': '&#x2F;',
+ '`': '&#x60;',
+ '=': '&#x3D;'
+ };
+
+ return String( html ).replace( /[&<>"'`=\/]/g, ( s, i, str ) => {
+ if( str.slice( i, i + 6 ).toLowerCase() === "<code>" ) return "<";
+ if( s === '<' ) {
+ console.log( s, i, str.slice( i, i + 7 ), str.slice( i, i + 7 ) == "</code>", str.slice( i, i + 6 ) == "<code>" );
+ if( str.slice( i, i + 6 ).toLowerCase() === "<code>"
+ || str.slice( i, i + 7 ).toLowerCase() === "</code>" ) {
+ console.log( "yes" );
+ return "<";
+ }
+ }
+
+ if( s === '>' ) {
+ console.log( s, i, str.slice( i - 6, i + 1 ), str.slice( i - 6, i + 1 ) == "</code>", str.slice( i - 5, i + 1 ) == "<code>" );
+ if( str.slice( i - 5, i + 1 ).toLowerCase() === "<code>"
+ || str.slice( i - 6, i + 1 ).toLowerCase() === "</code>" ) {
+ console.log( "yes" );
+ return ">";
+ }
+ }
+
+ if( s === '/' ) {
+ console.log( s, i, str.slice( i - 1, i + 6 ) );
+ if( str.slice( i - 1, i + 6 ).toLowerCase() === "</code>" ) {
+ console.log( "yes" );
+ return "/";
+ }
+ }
+
+ return entityMap[s];
+ });
+}
+
function replaceCodeTicks( text ) {
let inBlock = 0;
let tick = text.indexOf( "```" );
while( tick != -1 ) {
- if( inBlock == 0 ) {
+ if( !inBlock ) {
let second = text.slice( tick + 3 );
while( isWhiteChar( second[0] ) )
second = second.slice( 1 );
text = text.slice( 0, tick ) + "<code>" + second;
- tick = text.indexOf( "```", tick + 3 );
+ tick = text.indexOf( "```", tick );
} else {
let second = text.slice( tick + 3 );
while( second.length > 1 && isWhiteChar( second[0] ) && isWhiteChar( second[1] ) )
second = second.slice( 1 );
text = text.slice( 0, tick ) + "</code>" + second;
- tick = text.indexOf( "```", tick + 3 );
+ tick = text.indexOf( "```", tick );
}
inBlock = !inBlock;
}
- return text;
+ console.log( escapeHtml( text ) );
+
+ return escapeHtml( text );
}
function runHighlight() {
@@ -200,7 +251,7 @@ function createReadme( text, isMd ) {
th.innerHTML = "Readme";
tbody.insertBefore( th, tr );
- setTimeout( runHighlight );
+ //setTimeout( () => { setTimeout( runHighlight ) } );
}
function isCodeView( repo ) {
@@ -226,6 +277,7 @@ const main = async () => {
if( !isIndex( repo ) )
return;
+ const branch = branchFromForm();
const { file, isMd } = await getReadmeFile( repo, branch );
createReadme( file, isMd );
}