MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / interpret_markdown

Function interpret_markdown

crates/chat-cli/src/cli/chat/parse.rs:110–190  ·  view source on GitHub ↗
(
    mut i: Partial<&'a str>,
    mut o: impl Write + 'b,
    state: &mut ParseState,
)

Source from the content-addressed store, hash-verified

108}
109
110pub fn interpret_markdown<'a, 'b>(
111 mut i: Partial<&'a str>,
112 mut o: impl Write + 'b,
113 state: &mut ParseState,
114) -> PResult<Partial<&'a str>, Error<'a>> {
115 let mut error: Option<Error<'_>> = None;
116 let start = i.checkpoint();
117
118 macro_rules! stateful_alt {
119 ($($fns:ident),*) => {
120 $({
121 i.reset(&start);
122 match $fns(&mut o, state).parse_next(&mut i) {
123 Err(ErrMode::Backtrack(e)) => {
124 error = match error {
125 Some(error) => Some(error.or(e)),
126 None => Some(e),
127 };
128 },
129 res => {
130 return res.map(|_| i);
131 }
132 }
133 })*
134 };
135 }
136
137 match (state.in_codeblock, state.markdown_disabled.unwrap_or(false)) {
138 (_, true) => {
139 // If markdown is disabled, do not include markdown-related parsers
140 stateful_alt!(text, line_ending, fallback);
141 },
142 (false, false) => {
143 stateful_alt!(
144 // This pattern acts as a short circuit for alphanumeric plaintext
145 // More importantly, it's needed to support manual wordwrapping
146 text,
147 // multiline patterns
148 blockquote,
149 // linted_codeblock,
150 codeblock_begin,
151 // single line patterns
152 horizontal_rule,
153 heading,
154 bulleted_item,
155 numbered_item,
156 // inline patterns
157 code,
158 citation,
159 url,
160 bold,
161 italic,
162 strikethrough,
163 // symbols
164 less_than,
165 greater_than,
166 ampersand,
167 quot,

Callers 1

handle_responseMethod · 0.85

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected