Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TextDocument::from_markdown constructor #6109

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions crates/re_types/src/archetypes/text_document.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions crates/re_types/src/archetypes/text_document_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ impl TextDocument {
media_type,
})
}

/// Creates a new [`TextDocument`] containing Markdown.
///
/// Equivalent to `TextDocument::new(markdown).with_media_type(MediaType::markdown())`.
#[inline]
pub fn from_markdown(markdown: impl Into<crate::components::Text>) -> Self {
Self::new(markdown).with_media_type(MediaType::markdown())
}
}
3 changes: 1 addition & 2 deletions docs/snippets/all/text_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

rec.log(
"markdown",
&rerun::TextDocument::new(
&rerun::TextDocument::from_markdown(
r#"
# Hello Markdown!
[Click here to see the raw text](recording://markdown:Text).
Expand Down Expand Up @@ -47,7 +47,6 @@ Of course you can also have [normal https links](https://github.com/rerun-io/rer
![A random image](https://picsum.photos/640/480)
"#.trim(),
)
.with_media_type(rerun::MediaType::markdown()),
)?;

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions examples/rust/external_data_loader/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Example of an external data-loader executable plugin for the Rerun Viewer.
use rerun::{MediaType, EXTERNAL_DATA_LOADER_INCOMPATIBLE_EXIT_CODE};
use rerun::EXTERNAL_DATA_LOADER_INCOMPATIBLE_EXIT_CODE;

// The Rerun Viewer will always pass at least these two pieces of information:
// 1. The path to be loaded, as a positional arg.
Expand Down Expand Up @@ -106,7 +106,7 @@ fn main() -> anyhow::Result<()> {
rec.log_with_static(
entity_path_prefix.join(&rerun::EntityPath::from_file_path(&args.filepath)),
args.statically || args.timeless,
&rerun::TextDocument::new(text).with_media_type(MediaType::MARKDOWN),
&rerun::TextDocument::from_markdown(text),
)?;

Ok::<_, anyhow::Error>(())
Expand Down
5 changes: 1 addition & 4 deletions examples/rust/incremental_logging/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ Move the time cursor around, and notice how the colors and radii from frame 0 ar
"#;

fn run(rec: &rerun::RecordingStream) -> anyhow::Result<()> {
rec.log_static(
"readme",
&rerun::TextDocument::new(README).with_media_type(rerun::MediaType::MARKDOWN),
)?;
rec.log_static("readme", &rerun::TextDocument::from_markdown(README))?;

// TODO(#5264): just log one once clamp-to-edge semantics land.
let colors = [rerun::Color::from_rgb(255, 0, 0); 10];
Expand Down
11 changes: 3 additions & 8 deletions tests/rust/roundtrips/text_document/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
//! Logs a `Tensor` archetype for roundtrip checks.
use rerun::{
archetypes::TextDocument,
external::{re_log, re_types::components::MediaType},
RecordingStream,
};
use rerun::{archetypes::TextDocument, external::re_log, RecordingStream};

#[derive(Debug, clap::Parser)]
#[clap(author, version, about)]
Expand All @@ -17,15 +13,14 @@ fn run(rec: &RecordingStream, _args: &Args) -> anyhow::Result<()> {
rec.log("text_document", &TextDocument::new("Hello, TextDocument!"))?;
rec.log(
"markdown",
&TextDocument::new(
&TextDocument::from_markdown(
"# Hello\n\
Markdown with `code`!\n\
\n\
A random image:\n\
\n\
![A random image](https://picsum.photos/640/480)",
)
.with_media_type(MediaType::markdown()),
),
)?;
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions tests/rust/test_pinhole_projection/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! cargo run -p test_pinhole_projection
//! ```
use rerun::{external::re_log, MediaType, RecordingStream};
use rerun::{external::re_log, RecordingStream};

#[derive(Debug, clap::Parser)]
#[clap(author, version, about)]
Expand All @@ -31,7 +31,7 @@ fn run(rec: &RecordingStream) -> anyhow::Result<()> {
";
rec.log_static(
"description",
&rerun::TextDocument::new(DESCRIPTION).with_media_type(MediaType::markdown()),
&rerun::TextDocument::from_markdown(DESCRIPTION),
)?;

rec.log_static("world", &rerun::ViewCoordinates::RIGHT_HAND_Y_DOWN)?;
Expand Down
Loading