Browse Source

allow ascii // for archiphonemes

main
Rhiannon Morris 8 months ago
parent
commit
0a28afa10c
  1. 25
      langfilter/Spans.hs

25
langfilter/Spans.hs

@ -14,11 +14,12 @@ spans :: Vars => Inline -> IO Inline
spans = \case
Code attrs txt
| Just ('\\', txt') <- Text.uncons txt -> pure $ Code attrs txt'
| Just _ <- enclosed '/' '/' txt -> pure $ ipaB txt
| Just txt' <- enclosed '⫽' '⫽' txt -> pure $ ipaA txt'
| Just _ <- enclosed '[' ']' txt -> pure $ ipaN txt
| Just txt' <- enclosed '{' '}' txt -> lang txt'
| Just txt' <- enclosed '!' '!' txt -> pure $ abbr txt'
| Just txt' <- enclosed "" "" txt -> pure $ ipaA txt'
| Just txt' <- enclosed "//" "//" txt -> pure $ ipaA txt'
| Just _ <- enclosed "/" "/" txt -> pure $ ipaB txt
| Just _ <- enclosed "[" "]" txt -> pure $ ipaN txt
| Just txt' <- enclosed "{" "}" txt -> lang txt'
| Just txt' <- enclosed "!" "!" txt -> pure $ abbr txt'
i -> pure i
ipaA, ipaB, ipaN, abbr :: Text -> Inline
@ -27,6 +28,9 @@ ipaB = Span (cls ["ipa", "ipa-broad"]) . text'
ipaN = Span (cls ["ipa", "ipa-narrow"]) . text'
abbr = Span (cls ["abbr"]) . text' . endash
surround :: Text -> Text -> Text
surround s txt = s <> txt <> s
text' :: Text -> [Inline]
text' = toList . text
@ -60,12 +64,13 @@ cls :: [Text] -> Attr
cls cs = ("", cs, [])
enclosed :: Char -> Char -> Text -> Maybe Text
enclosed :: Text -> Text -> Text -> Maybe Text
enclosed o c txt
| Text.length txt >= 2,
Text.head txt == o,
Text.last txt == c
= Just $ Text.init $ Text.tail txt
| Text.length txt >= ℓo + ℓc,
Text.take ℓo txt == o,
Text.takeEnd ℓc txt == c
= Just $ Text.drop ℓo $ Text.dropEnd ℓc txt
where ℓo = Text.length o; ℓc = Text.length c
enclosed _ _ _ = Nothing

Loading…
Cancel
Save