docs.fs_cleanStringForAnchorId - FN

type: FN ( scalar function ), modify_date: 2021-12-22 12:54:24

RepoObject_guid: 667159E3-27E6-EB11-8507-A81E8446D5B0

Description

Examples

Parameters

  • (nvarchar(4000))

  • @source_string (nvarchar(4000))

Entity Diagram

entity-docs.fs_cleanstringforanchorid

sql_modules_definition

docs.fs_cleanStringForAnchorId - FN script
/*
allowed characters in ID see the link from here
https://docs.asciidoctor.org/asciidoc/latest/sections/ids/#how-a-section-id-is-assembled
to here
https://www.w3.org/TR/REC-xml/#NT-Name

'_' and '-' could be used. but they work fine only if the are solo, but not as double '__' or '--'
`[#abc_d-e]` works fine, the right way
`[id=abc_d-e]` works fine, the right way, maybe it could also support blanks?
`[[abc_d-e]]` works fine, but deprecated
`[id:abc_d-e]` doesn't support '-', maybe it not the right syntqax at all

there could be additinal issues with äüö and so on, if this happens, we will need to add replacements here
*/
CREATE FUNCTION [docs].[fs_cleanStringForAnchorId]
(
    @source_string NVarchar(4000)
)
Returns NVarchar(4000)
As
Begin
    Return
	Lower (
	Replace ( Replace ( Replace ( Replace ( Replace ( Replace (  Replace (Replace ( Replace ( Replace ( Replace ( Replace ( Replace ( Replace ( Replace ( Replace ( Replace ( Replace ( Replace ( Replace (
		Trim( @source_string )
		, ' ', 'blank' )
		, '+', 'plus' )
		, '-', 'minus' )
		, '_', 'underline' )
		, '#', 'hash' )
		, '&', 'amp' )
		, '(', 'startb' )
		, ')', 'endb' )
		, '[', 'startsb' )
		, ']', 'endsb' )
		, '/', 'slash' )
		, '\', 'backslash' )
		, ',', 'comma' )
		, '.', 'dot' )
		, '?', 'questionmark' )
		, '*', 'star' )
		, '%', 'percent' )
		, '|', 'vbar')
		, '`', 'backtick')
		, ':', 'colon' )
	--Lower:
	)
End;