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
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