From ee5130bd16e534720cab4797ecd55438165d12da Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Fri, 11 Aug 2023 11:40:20 +0200 Subject: [PATCH] Fix relative links from README in rustdoc (#78) --- README.md | 12 +++++++++--- src/lib.rs | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 68457c8..4890712 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ test suite](https://github.com/html5lib/html5lib-tests/tree/master/tokenizer). S * `html5gum` doesn't implement the DOM, and unfortunately in the HTML spec, constructing the DOM ("tree construction") influences how tokenization is done. For an example of which problems this causes see [this example - code](./examples/tokenize_with_state_switches.rs). + code][examples/tokenize_with_state_switches.rs]. * `html5gum` **does not** generally qualify as a browser-grade HTML *parser* as per the WHATWG spec. This can change in the future, see [issue 21](https://github.com/untitaker/html5gum/issues/21). @@ -69,7 +69,7 @@ This allows you to: you, you can implement the respective trait methods as noop and therefore avoid any overhead creating plaintext tokens. -See [the `custom_emitter` example](./examples/custom_emitter.rs) for how this +See [the `custom_emitter` example][examples/custom_emitter.rs] for how this looks like in practice. ## Other features @@ -109,4 +109,10 @@ Why is this library called `html5gum`? ## License -Licensed under the MIT license, see [`./LICENSE`](./LICENSE). +Licensed under the MIT license, see [`./LICENSE`][LICENSE]. + + + +[LICENSE]: ./LICENSE +[examples/tokenize_with_state_switches.rs]: ./examples/tokenize_with_state_switches.rs +[examples/custom_emitter.rs]: ./examples/custom_emitter.rs diff --git a/src/lib.rs b/src/lib.rs index 68caef8..295c2f5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,13 @@ #![warn(missing_docs)] // This is an HTML parser. HTML can be untrusted input from the internet. #![forbid(unsafe_code)] +// +// Relative links in the README.md don't work in rustdoc, so we have to override them. +#![doc = concat!("[LICENSE]: ", blob_url_prefix!(), "LICENSE")] +#![doc = concat!("[examples/tokenize_with_state_switches.rs]: ", blob_url_prefix!(), "examples/tokenize_with_state_switches.rs")] +#![doc = concat!("[examples/custom_emitter.rs]: ", blob_url_prefix!(), "examples/custom_emitter.rs")] #![doc = include_str!("../README.md")] +// #![warn(clippy::all)] #![warn( absolute_paths_not_starting_with_crate, @@ -16,6 +22,16 @@ #![allow(clippy::module_name_repetitions)] #![allow(clippy::missing_errors_doc)] +macro_rules! blob_url_prefix { + () => { + concat!( + "https://github.com/untitaker/html5gum/blob/", + env!("CARGO_PKG_VERSION"), + "/" + ) + }; +} + mod arrayvec; mod char_validator; mod emitter;