Skip to content

Commit

Permalink
Add TextDocument::from_markdown constructor (#6109)
Browse files Browse the repository at this point in the history
### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6109?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6109?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!

- [PR Build Summary](https://build.rerun.io/pr/6109)
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)

To run all checks from `main`, comment on the PR with `@rerun-bot
full-check`.
  • Loading branch information
emilk authored Apr 25, 2024
1 parent 10753fa commit fe11d0c
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 20 deletions.
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

0 comments on commit fe11d0c

Please sign in to comment.