File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed
src/RestructuredText/Parser/References Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change 1414namespace phpDocumentor \Guides \RestructuredText \Parser \References ;
1515
1616use function preg_match ;
17+ use function trim ;
1718
1819trait EmbeddedReferenceParser
1920{
21+ /**
22+ * https://regex101.com/r/KadqKx/1
23+ */
24+ private string $ referenceRegex = '/^(.*?)(<([^<]+)>)?$/s ' ;
25+
2026 private function extractEmbeddedReference (string $ text ): ReferenceData
2127 {
22- preg_match (' /^(.*?)(?:(?:\s|^)<([^<]+)>)?$/s ' , $ text , $ matches );
28+ preg_match ($ this -> referenceRegex , $ text , $ matches );
2329
24- $ text = $ matches [1 ] === '' ? null : $ matches [1 ];
25- $ reference = $ matches [1 ];
30+ $ text = $ matches [1 ] === '' ? null : trim ( $ matches [1 ]) ;
31+ $ reference = trim ( $ matches [1 ]) ;
2632
27- if (isset ($ matches [2 ])) {
33+ if (isset ($ matches [3 ])) {
2834 // there is an embedded URI, text and URI are different
29- $ reference = $ matches [2 ];
35+ $ reference = $ matches [3 ];
3036 } else {
3137 $ text = null ;
3238 }
You can’t perform that action at this time.
0 commit comments