From 9fd2b4699d9697b87fabcf982184ce6c381634f0 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Sun, 4 Dec 2022 23:46:24 +1300 Subject: [PATCH] Optimise update-tree-wiki somewhat --- src/page-wiki.rkt | 233 +------------------------------------ src/tree-updater.rkt | 267 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 272 insertions(+), 228 deletions(-) create mode 100644 src/tree-updater.rkt diff --git a/src/page-wiki.rkt b/src/page-wiki.rkt index 2cd14dc..6f22ad8 100644 --- a/src/page-wiki.rkt +++ b/src/page-wiki.rkt @@ -19,6 +19,7 @@ "data.rkt" "pure-utils.rkt" "syntax.rkt" + "tree-updater.rkt" "xexpr-utils.rkt" "url-utils.rkt") @@ -30,51 +31,19 @@ preprocess-html-wiki) (module+ test - (require rackunit) - (define wiki-document - '(*TOP* - (div (@ (class "mw-parser-output")) - (aside (@ (role "region") (class "portable-infobox pi-theme-wikia pi-layout-default")) - (h2 (@ (class "pi-item pi-title") (data-source "title")) - "Infobox Title") - (figure (@ (class "pi-item pi-image") (data-source "image")) - (a (@ (href "https://static.wikia.nocookie.net/nice-image.png") (class "image image-thumbnail") (title "")) - (img (@ (src "https://static.wikia.nocookie.net/nice-image-thumbnail.png") (class "pi-image-thumbnail"))))) - (div (@ (class "pi-item pi-data") (data-source "description")) - (h3 (@ (class "pi-data-label")) - "Description") - (div (@ (class "pi-data-value")) - "Mystery infobox!"))) - (div (@ (data-test-collapsesection) (class "collapsible collapsetoggle-inline collapsed")) - (i (b "This section is hidden for dramatic effect.")) - (div (@ (class "collapsible-content")) - (p "Another page link: " - (a (@ (data-test-wikilink) (href "https://test.fandom.com/wiki/Another_Page") (title "Another Page")) - "Another Page")))) - (figure (@ (class "thumb tnone")) - (a (@ (href "https://static.wikia.nocookie.net/nice-image.png") (class "image") (data-test-figure-a)) - (img (@ (src "data:image/gif;base64,R0lGODlhAQABAIABAAAAAP///yH5BAEAAAEALAAAAAABAAEAQAICTAEAOw%3D%3D") - (data-src "https://static.wikia.nocookie.net/nice-image-thumbnail.png") - (class "thumbimage lazyload")))) - (noscript - (a (@ (href "https://static.wikia.nocookie.net/nice-image.png") (class "image")) - (img (@ (src "https://static.wikia.nocookie.net/nice-image-thumbnail.png") - (data-src "https://static.wikia.nocookie.net/nice-image-thumbnail.png") - (class "thumbimage"))))) - (figcaption "Test figure!")) - (iframe (@ (src "https://example.com/iframe-src"))))))) + (require rackunit)) (define (preprocess-html-wiki html) - (define (rr* find replace contents) + (define ((rr* find replace) contents) (regexp-replace* find contents replace)) ((compose1 ; fix navbox list nesting ; navbox on right of page has incorrect html "
  • " and the xexpr parser puts the
  • much further up the tree ; add a