mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-22 16:08:13 +00:00
remove unwanted spacing around the list in block editor (#19521)
* remove unwanted spacing around the list in block editor * fix spacing issue --------- Co-authored-by: karanh37 <karanh37@gmail.com>
This commit is contained in:
parent
33c107dea0
commit
13f3d19b5d
@ -10,7 +10,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { getTextFromHtmlString } from './BlockEditorUtils';
|
||||
import {
|
||||
getHtmlStringFromMarkdownString,
|
||||
getTextFromHtmlString,
|
||||
} from './BlockEditorUtils';
|
||||
|
||||
describe('getTextFromHtmlString', () => {
|
||||
it('should return empty string when input is undefined', () => {
|
||||
@ -72,3 +75,45 @@ describe('getTextFromHtmlString', () => {
|
||||
expect(getTextFromHtmlString(input)).toBe(output);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getHtmlStringFromMarkdownString', () => {
|
||||
it('should return the same string if input is already HTML', () => {
|
||||
const input = '<p>Hello World</p>';
|
||||
|
||||
expect(getHtmlStringFromMarkdownString(input)).toBe(input);
|
||||
});
|
||||
|
||||
it('should convert markdown to HTML', () => {
|
||||
const input = 'Hello **World**';
|
||||
const expectedOutput = '<p>Hello <strong>World</strong></p>';
|
||||
|
||||
expect(getHtmlStringFromMarkdownString(input)).toBe(expectedOutput);
|
||||
});
|
||||
|
||||
it('should handle empty string', () => {
|
||||
expect(getHtmlStringFromMarkdownString('')).toBe('');
|
||||
});
|
||||
|
||||
it('should preserve special characters in markdown', () => {
|
||||
const input = 'Hello & World! @ #$%^';
|
||||
const expectedOutput = '<p>Hello & World! @ #$%^</p>';
|
||||
|
||||
expect(getHtmlStringFromMarkdownString(input)).toBe(expectedOutput);
|
||||
});
|
||||
|
||||
it('should handle complex markdown structure', () => {
|
||||
const input = `
|
||||
## Demo Title
|
||||
Small Subtitle.
|
||||
- Item 1
|
||||
- Item 2
|
||||
`;
|
||||
const expectedOutput = `
|
||||
<pre><code>##DemoTitleSmallSubtitle.-Item1-Item2</code></pre>
|
||||
`;
|
||||
|
||||
expect(getHtmlStringFromMarkdownString(input).replace(/\s+/g, '')).toBe(
|
||||
expectedOutput.replace(/\s+/g, '')
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -139,6 +139,12 @@ const _convertMarkdownStringToHtmlString = new Showdown.Converter({
|
||||
ellipsis: false,
|
||||
});
|
||||
|
||||
export const getHtmlStringFromMarkdownString = (content: string) => {
|
||||
return isHTMLString(content)
|
||||
? content
|
||||
: _convertMarkdownStringToHtmlString.makeHtml(content);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the content of the editor
|
||||
* @param editor The editor instance
|
||||
@ -146,7 +152,7 @@ const _convertMarkdownStringToHtmlString = new Showdown.Converter({
|
||||
*/
|
||||
export const setEditorContent = (editor: Editor, newContent: string) => {
|
||||
// Convert the markdown string to an HTML string
|
||||
const htmlString = _convertMarkdownStringToHtmlString.makeHtml(newContent);
|
||||
const htmlString = getHtmlStringFromMarkdownString(newContent);
|
||||
|
||||
editor.commands.setContent(htmlString);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user