lodash#unescape TypeScript Examples

The following examples show how to use lodash#unescape. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: documentation.ts    From ui5-language-assistant with Apache License 2.0 5 votes vote down vote up
tagMatcherToReplacement: {
  matcher: RegExp;
  replacement: Record<ConvertTarget, string | ReplaceFunction>;
}[] = [
  // Italics
  {
    matcher: /<i>(.+?)<\/i>/g,
    replacement: { markdown: "*$1*", plaintext: "$1" },
  },

  // Bold
  {
    matcher: /<b>(.+?)<\/b>/g,
    replacement: { markdown: "**$1**", plaintext: "$1" },
  },
  {
    matcher: /<strong>(.+?)<\/strong>/g,
    replacement: { markdown: "**$1**", plaintext: "$1" },
  },

  // Emphasis
  {
    matcher: /<em>(.+?)<\/em>/g,
    replacement: { markdown: "***$1***", plaintext: "$1" },
  },

  // Headers
  {
    matcher: /<h1>(.+?)<\/h1>/g,
    replacement: { markdown: "\n# $1\n\n", plaintext: "\n$1\n" },
  },
  {
    matcher: /<h2>(.+?)<\/h2>/g,
    replacement: { markdown: "\n## $1\n\n", plaintext: "\n$1\n" },
  },
  {
    matcher: /<h3>(.+?)<\/h3>/g,
    replacement: { markdown: "\n### $1\n\n", plaintext: "\n$1\n" },
  },
  {
    matcher: /<h4>(.+?)<\/h4>/g,
    replacement: { markdown: "\n#### $1\n\n", plaintext: "\n$1\n" },
  },

  // Lists
  {
    matcher: /<li>(.+?)<\/li>/g,
    replacement: { markdown: "\n* $1", plaintext: "\n* $1" },
  },
  { matcher: /<ul>/g, replacement: { markdown: "", plaintext: "" } },
  { matcher: /<\/ul>/g, replacement: { markdown: "\n\n", plaintext: "\n" } },
  // TODO should we handle ordered lists (ol)?

  // Code value
  {
    matcher: /<code>(.+?)<\/code>/g,
    replacement: { markdown: "`$1`", plaintext: "$1" },
  },

  // Code block
  {
    matcher: /<pre>([^]+?)<\/pre>/g,
    replacement: {
      markdown: "\n```javascript\n$1```\n",
      plaintext: "\n$1\n",
    },
  },

  // Line break
  { matcher: /<br\/>/g, replacement: { markdown: "\n", plaintext: "\n" } },
  { matcher: /<br>/g, replacement: { markdown: "\n", plaintext: "\n" } },
  { matcher: /<\/br>/g, replacement: { markdown: "\n", plaintext: "\n" } },

  // HTML Escaping, e.g. "&lt;View" --> "<View"
  // Note: this doesn't replace all html-encoded characters, only the most common ones
  {
    matcher: /.*/gm,
    replacement: { markdown: unescape, plaintext: unescape },
  },
]
Example #2
Source File: parseReactBlockToBlockData.ts    From easy-email with MIT License 5 votes vote down vote up
export function parseReactBlockToBlockData<T extends IBlockData = IBlockData>(
  node: React.ReactElement
) {
  return JSON.parse(unescape(renderToStaticMarkup(node))) as T;
}
Example #3
Source File: useEventsQuery.ts    From backstage with Apache License 2.0 5 votes vote down vote up
useEventsQuery = ({
  selectedCalendars = [],
  calendars = [],
  enabled,
  timeMin,
  timeMax,
  timeZone,
}: Options) => {
  const calendarApi = useApi(gcalendarApiRef);
  const eventQueries = useQueries(
    selectedCalendars
      .filter(id => calendars.find(c => c.id === id))
      .map(calendarId => {
        const calendar = calendars.find(c => c.id === calendarId);

        return {
          queryKey: ['calendarEvents', calendarId, timeMin, timeMax],
          enabled,
          initialData: [],
          refetchInterval: 60000,
          refetchIntervalInBackground: true,
          queryFn: async (): Promise<GCalendarEvent[]> => {
            const data = await calendarApi.getEvents(calendarId, {
              calendarId,
              timeMin,
              timeMax,
              showDeleted: false,
              singleEvents: true,
              maxResults: 100,
              orderBy: 'startTime',
              timeZone,
            });

            return (data.items || []).map(event => {
              const responseStatus = event.attendees?.find(
                a => !!a.self,
              )?.responseStatus;

              return {
                ...event,
                summary: unescape(event.summary || ''),
                calendarId,
                backgroundColor: calendar?.backgroundColor,
                primary: !!calendar?.primary,
                responseStatus,
              };
            });
          },
        };
      }),
  );

  const events = useMemo(
    () => compact(eventQueries.map(({ data }) => data).flat()),
    [eventQueries],
  );

  const isLoading =
    !!eventQueries.find(q => q.isFetching) && events.length === 0;

  return { events, isLoading };
}