@@ -7,7 +7,7 @@ import { LiteralReprAll, LiteralTypeOrAll } from "./binaryop";
7
7
import { Context } from "./context" ;
8
8
import { Fields } from "./field" ;
9
9
import { EXPRESSION } from "./parse" ;
10
- import { escapeRegex } from "util/normalize" ;
10
+ import { escapeRegex , normalizeMarkdown } from "util/normalize" ;
11
11
import { DataArray } from "api/data-array" ;
12
12
import { cyrb53 } from "util/hash" ;
13
13
@@ -701,6 +701,25 @@ export namespace DefaultFunctions {
701
701
. add2 ( "*" , "*" , ( v , bk ) => ( Values . isNull ( v ) ? bk : v ) )
702
702
. build ( ) ;
703
703
704
+ // Returns the display name of the element.
705
+ export const display = new FunctionBuilder ( "display" )
706
+ . add1 ( "null" , ( ) : Literal => "" )
707
+ . add1 ( "array" , ( a : Literal [ ] , ctx : Context ) : Literal => {
708
+ return a . map ( e => display ( ctx , e ) ) . join ( ", " ) ;
709
+ } )
710
+ . add1 ( "string" , ( str : string ) : Literal => normalizeMarkdown ( str ) )
711
+ . add1 ( "link" , ( a : Link , ctx : Context ) : Literal => {
712
+ if ( a . display ) {
713
+ return display ( ctx , a . display ) ;
714
+ } else {
715
+ return Values . toString ( a , ctx . settings ) . replace ( / \[ \[ .* \| ( .* ) \] \] / , "$1" )
716
+ }
717
+ } )
718
+ . add1 ( "*" , ( a : Literal , ctx : Context ) : Literal => {
719
+ return Values . toString ( a , ctx . settings ) ;
720
+ } )
721
+ . build ( ) ;
722
+
704
723
export const choice = new FunctionBuilder ( "choice" )
705
724
. add3 ( "*" , "*" , "*" , ( b , left , right ) => ( Values . isTruthy ( b ) ? left : right ) )
706
725
. vectorize ( 3 , [ 0 ] )
@@ -930,6 +949,7 @@ export const DEFAULT_FUNCTIONS: Record<string, FunctionImpl> = {
930
949
// Utility Operations
931
950
default : DefaultFunctions . fdefault ,
932
951
ldefault : DefaultFunctions . ldefault ,
952
+ display : DefaultFunctions . display ,
933
953
choice : DefaultFunctions . choice ,
934
954
striptime : DefaultFunctions . striptime ,
935
955
dateformat : DefaultFunctions . dateformat ,
0 commit comments