allow ascii // for archiphonemes

This commit is contained in:
Rhiannon Morris 2021-06-04 05:38:15 +02:00
parent 1b382aa5c9
commit 0a28afa10c

View file

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