From 8f54b7a0753d73243e92fe9e186116ebeb8e8fc5 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Fri, 1 Jan 2021 14:46:27 +1300 Subject: [PATCH] Allow linking to any element on a webpage, regardless of whether it has an ID --- src/Render.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Render.hs b/src/Render.hs index 750eb8a..9176343 100644 --- a/src/Render.hs +++ b/src/Render.hs @@ -11,6 +11,7 @@ import System.Directory as Dir import Data.FileEmbed import Data.Maybe (fromMaybe, maybeToList) +import Text.Read (readMaybe) import Debug.Trace (trace) --- External Rhapsode subcomponents @@ -108,6 +109,19 @@ loadUserStyles styles = do targetSel "" = [CSSTok.Ident "main"] targetSel "#" = [CSSTok.Colon, CSSTok.Ident "root"] +targetSel ('#':'.':anchor) = + CSSTok.Colon : CSSTok.Ident "root" : concat [ selLayer n | n <- path anchor] + where + path ('.':anchor) = [] : path anchor + path (c:anchor) | n:path' <- path anchor, c >= '0' && c <= '9' = (c:n):path' + path [] = [[]] + path _ = [] + + selLayer n = [ + CSSTok.Delim '>', + CSSTok.Colon, CSSTok.Function "nth-child", + CSSTok.Number (pack n) (CSSTok.NVInteger $ fromMaybe 0 $ readMaybe n), + CSSTok.RightParen] targetSel ('#':id) = [CSSTok.Hash CSSTok.HUnrestricted $ Txt.pack id] targetSel _ = [] -- 2.30.2