@@ -227,6 +227,7 @@ pub struct Snippet<'a, T> {
227227 pub ( crate ) line_start : usize ,
228228 pub ( crate ) source : Cow < ' a , str > ,
229229 pub ( crate ) markers : Vec < T > ,
230+ pub ( crate ) url : Option < Cow < ' a , str > > ,
230231 pub ( crate ) fold : bool ,
231232}
232233
@@ -246,6 +247,7 @@ impl<'a, T: Clone> Snippet<'a, T> {
246247 line_start : 1 ,
247248 source : source. into ( ) ,
248249 markers : vec ! [ ] ,
250+ url : None ,
249251 fold : true ,
250252 }
251253 }
@@ -271,6 +273,19 @@ impl<'a, T: Clone> Snippet<'a, T> {
271273 self
272274 }
273275
276+ /// The URL to the [`source`][Self::source]. Can be a `file://` URL.
277+ ///
278+ /// Make sure to follow [the OSC 8 reference document][OSC-8], and in
279+ /// particular the [`file://` URIs and the hostname][OSC-8-file-URIs] when
280+ /// generating a `file://` URL.
281+ ///
282+ /// [OSC-8]: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
283+ /// [OSC-8-file-URIs]: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda#file-uris-and-the-hostname
284+ pub fn path_url ( mut self , url : impl Into < OptionCow < ' a > > ) -> Self {
285+ self . url = url. into ( ) . 0 ;
286+ self
287+ }
288+
274289 /// Control whether lines without [`Annotation`]s are shown
275290 ///
276291 /// The default is `fold(true)`, collapsing uninteresting lines.
@@ -487,6 +502,7 @@ pub struct Origin<'a> {
487502 pub ( crate ) path : Cow < ' a , str > ,
488503 pub ( crate ) line : Option < usize > ,
489504 pub ( crate ) char_column : Option < usize > ,
505+ pub ( crate ) url : Option < Cow < ' a , str > > ,
490506}
491507
492508impl < ' a > Origin < ' a > {
@@ -502,6 +518,7 @@ impl<'a> Origin<'a> {
502518 path : path. into ( ) ,
503519 line : None ,
504520 char_column : None ,
521+ url : None ,
505522 }
506523 }
507524
@@ -522,6 +539,19 @@ impl<'a> Origin<'a> {
522539 self . char_column = Some ( char_column) ;
523540 self
524541 }
542+
543+ /// The URL to the origin. Can be a `file://` URL.
544+ ///
545+ /// Make sure to follow [the OSC 8 reference document][OSC-8], and in
546+ /// particular the [`file://` URIs and the hostname][OSC-8-file-URIs] when
547+ /// generating a `file://` URL.
548+ ///
549+ /// [OSC-8]: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
550+ /// [OSC-8-file-URIs]: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda#file-uris-and-the-hostname
551+ pub fn path_url ( mut self , uri : impl Into < Cow < ' a , str > > ) -> Self {
552+ self . url = Some ( uri. into ( ) ) ;
553+ self
554+ }
525555}
526556
527557impl < ' a > From < Cow < ' a , str > > for Origin < ' a > {
0 commit comments