Add Markdownv2 support to td_api::parseTextEntities.

GitOrigin-RevId: 79fc37ce5f1c243150433dca54ff915c55ce884d
This commit is contained in:
levlam 2019-10-03 02:39:10 +03:00
parent fdf70df492
commit 5a07029e6b
4 changed files with 15 additions and 6 deletions

View File

@ -2575,7 +2575,8 @@ deepLinkInfo text:formattedText need_update_application:Bool = DeepLinkInfo;
//@class TextParseMode @description Describes the way the text should be parsed for TextEntities
//@description The text should be parsed in markdown-style
textParseModeMarkdown = TextParseMode;
//@version Version of the parser, 0 - Bot API 1.0 parser, 1 - Bot API 4.5 rules with underline, strikethrough and nested entities support
textParseModeMarkdown version:int32 = TextParseMode;
//@description The text should be parsed in HTML-style
textParseModeHTML = TextParseMode;

Binary file not shown.

View File

@ -7656,8 +7656,16 @@ td_api::object_ptr<td_api::Object> Td::do_static_request(td_api::parseTextEntiti
switch (request.parse_mode_->get_id()) {
case td_api::textParseModeHTML::ID:
return parse_html(request.text_);
case td_api::textParseModeMarkdown::ID:
return parse_markdown(request.text_);
case td_api::textParseModeMarkdown::ID: {
auto version = static_cast<const td_api::textParseModeMarkdown *>(request.parse_mode_.get())->version_;
if (version == 0) {
return parse_markdown(request.text_);
}
if (version == 1) {
return parse_markdown_v2(request.text_);
}
return Status::Error("Wrong Markdown version specified");
}
default:
UNREACHABLE();
return Status::Error(500, "Unknown parse mode");

View File

@ -901,7 +901,7 @@ class CliClient final : public Actor {
string text, vector<td_api::object_ptr<td_api::textEntity>> entities = {}) {
if (entities.empty() && !text.empty()) {
auto parsed_text = execute(
td_api::make_object<td_api::parseTextEntities>(text, td_api::make_object<td_api::textParseModeMarkdown>()));
td_api::make_object<td_api::parseTextEntities>(text, td_api::make_object<td_api::textParseModeMarkdown>(1)));
if (parsed_text->get_id() == td_api::formattedText::ID) {
return td_api::move_object_as<td_api::formattedText>(parsed_text);
}
@ -2563,13 +2563,13 @@ class CliClient final : public Actor {
execute(td_api::make_object<td_api::getTextEntities>(args));
} else if (op == "pte") {
send_request(
td_api::make_object<td_api::parseTextEntities>(args, td_api::make_object<td_api::textParseModeMarkdown>()));
td_api::make_object<td_api::parseTextEntities>(args, td_api::make_object<td_api::textParseModeMarkdown>(1)));
} else if (op == "pteh") {
send_request(
td_api::make_object<td_api::parseTextEntities>(args, td_api::make_object<td_api::textParseModeHTML>()));
} else if (op == "ptes") {
execute(
td_api::make_object<td_api::parseTextEntities>(args, td_api::make_object<td_api::textParseModeMarkdown>()));
td_api::make_object<td_api::parseTextEntities>(args, td_api::make_object<td_api::textParseModeMarkdown>(1)));
} else if (op == "ptehs") {
execute(td_api::make_object<td_api::parseTextEntities>(args, td_api::make_object<td_api::textParseModeHTML>()));
} else if (op == "gfmt") {