Explorar el Código

#79940 create flag and fix regex

SULLEY\ryo-h hace 4 años
padre
commit
735d107144

+ 3 - 1
packages/app/src/components/SearchPage/SearchResultListItem.tsx

@@ -28,8 +28,10 @@ const SearchResultListItem: FC<Props> = (props:Props) => {
   // Add prefix 'id_' in pageId, because scrollspy of bootstrap doesn't work when the first letter of id attr of target component is numeral.
   const pageId = `#${page._id}`;
 
+  const isPathHighlighted = props.page.elasticSearchResult.highlightedPath != null;
+
   const dPagePath = new DevidedPagePath(page.path, false, true);
-  const pagePathElem = <PagePathLabel path={props.page.elasticSearchResult.highlightedPath} isFormerOnly />;
+  const pagePathElem = <PagePathLabel path={props.page.elasticSearchResult.highlightedPath} isFormerOnly isPathHighlighted={isPathHighlighted} />;
 
   // TODO : send cetain  length of body (revisionBody) from elastisearch by adding some settings to the query and
   //         when keyword is not in page content, display revisionBody.

+ 1 - 1
packages/core/src/models/devided-page-path.js

@@ -3,7 +3,7 @@ import * as pathUtils from '../utils/path-utils';
 // https://regex101.com/r/BahpKX/2
 const PATTERN_INCLUDE_DATE = /^(.+\/[^/]+)\/(\d{4}|\d{4}\/\d{2}|\d{4}\/\d{2}\/\d{2})$/;
 // https://regex101.com/r/HJNvMW/1
-const PATTERN_DEFAULT = /^((.*)(?<!<)\/)?(.+)$/gm;
+const PATTERN_DEFAULT = /^((.*)(?<!<)\/)?(.+)$/;
 // https://regex101.com/r/4J4JuR/1
 const PATTERN_PATH_WITH_ANY_HTML_TAGS = /<("[^"]*"|'[^']*'|[^'">])*>/g;
 

+ 7 - 2
packages/ui/src/components/PagePath/PagePathLabel.jsx

@@ -10,10 +10,14 @@ export const PagePathLabel = (props) => {
   classNames = classNames.concat(props.additionalClassNames);
 
   const displayPath = (reactElement) => {
-    // eslint-disable-next-line react/no-danger
-    return <span dangerouslySetInnerHTML={{ __html: reactElement.props.children }}></span>;
+    if (props.isPathHighlighted) {
+      // eslint-disable-next-line react/no-danger
+      return <span dangerouslySetInnerHTML={{ __html: reactElement.props.children }}></span>;
+    }
+    return <span className={classNames.join(' ')}>{reactElement.props.children}</span>;
   };
 
+
   if (props.isLatterOnly) {
     return displayPath(<>{dPagePath.latter}</>);
   }
@@ -35,6 +39,7 @@ export const PagePathLabel = (props) => {
 PagePathLabel.propTypes = {
   isLatterOnly: PropTypes.bool,
   isFormerOnly: PropTypes.bool,
+  isPathHighlighted: PropTypes.bool,
   additionalClassNames: PropTypes.arrayOf(PropTypes.string),
   path: PropTypes.string.isRequired,
 };