Files
AFFiNE-Mirror/blocksuite/framework/std/src/inline/utils/attribute-renderer.ts
T
L-Sun 46a9d0f7fe fix(editor): commented heading style (#13140)
Close BS-3613

#### PR Dependency Tree


* **PR #13140** 👈

This tree was auto-generated by
[Charcoal](https://github.com/danerwilliams/charcoal)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Style**
* Updated default text styling to inherit font weight, style, and
decoration from parent elements when bold, italic, underline, or strike
attributes are not set. This may result in text more closely matching
its surrounding context.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-07-10 11:12:20 +00:00

50 lines
1.4 KiB
TypeScript

import type { BaseTextAttributes } from '@blocksuite/store';
import { html } from 'lit';
import { styleMap } from 'lit/directives/style-map.js';
import type { AttributeRenderer } from '../types.js';
function inlineTextStyles(
props: BaseTextAttributes
): ReturnType<typeof styleMap> {
let textDecorations = '';
if (props.underline) {
textDecorations += 'underline';
}
if (props.strike) {
textDecorations += ' line-through';
}
let inlineCodeStyle = {};
if (props.code) {
inlineCodeStyle = {
'font-family':
'"SFMono-Regular", Menlo, Consolas, "PT Mono", "Liberation Mono", Courier, monospace',
'line-height': 'normal',
background: 'rgba(135,131,120,0.15)',
color: '#EB5757',
'border-radius': '3px',
'font-size': '85%',
padding: '0.2em 0.4em',
};
}
return styleMap({
'font-weight': props.bold ? 'bold' : 'inherit',
'font-style': props.italic ? 'italic' : 'inherit',
'text-decoration': textDecorations.length > 0 ? textDecorations : 'inherit',
...inlineCodeStyle,
});
}
export const getDefaultAttributeRenderer =
<T extends BaseTextAttributes>(): AttributeRenderer<T> =>
({ delta }) => {
const style = delta.attributes
? inlineTextStyles(delta.attributes)
: styleMap({});
return html`<span style=${style}
><v-text .str=${delta.insert}></v-text
></span>`;
};