-- | Give a node a unique id
--
-- Might be handy to build server-side react-esque systems
note :: (Markup t a -> Markup t b) -> Markup t a -> Markup t (Note t, b)
note f x = withNote
  where
    withNote = do
      (i, a) <- markup
      case runM i markup of
        (m', _, _) -> return (Note
          { noteId = i
          , noted = compile_ m'
          }, a)

    markup = Markup $ \i attrs -> case f x of
      Markup m ->
        case m (i + 1) ("id" := niceId i:attrs) of
          ms -> ms { msResult = (i, msResult ms) }

-- | HTML 'id' attribute given to 'note'd elements.
note :: (Markup t a -> Markup t b) -> Markup t a -> Markup t (Note t, b)
note f x = withNote
  where
    withNote = do
      (i, a) <- markup
      case runM i markup of
        (m', _, _) -> return (Note
          { noteId = i
          , noted = compile_ m'
          }, a)

    markup = Markup $ \i attrs -> case f x of
      Markup m ->
        case m (i + 1) ("id" := niceId i:attrs) of
          ms -> ms { msResult = (i, msResult ms) }

-- | HTML 'id' attribute given to 'note'd elements.
note f x = withNote
  where
    withNote = do
      (i, a) <- markup
      case runM i markup of
        (m', _, _) -> return (Note
          { noteId = i
          , noted = compile_ m'
          }, a)

    markup = Markup $ \i attrs -> case f x of
      Markup m ->
        case m (i + 1) ("id" := niceId i:attrs) of
          ms -> ms { msResult = (i, msResult ms) }

-- | HTML 'id' attribute given to 'note'd elements.