markdown_style.dart 2.63 KB
Newer Older
1 2 3 4 5
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
6
import 'markdown.dart';
7 8 9 10 11 12 13 14 15
import 'markdown_style_raw.dart';

/// Style used for rendering markdown formatted text using the [MarkdownBody]
/// widget.
class MarkdownStyle extends MarkdownStyleRaw{

  /// Creates a [MarkdownStyle] from the [TextStyle]s in the provided [theme].
  MarkdownStyle.defaultFromTheme(ThemeData theme) : super(
    a: new TextStyle(color: Colors.blue[500]),
16
    p: theme.textTheme.body1,
17 18 19
    code: new TextStyle(
      color: Colors.grey[700],
      fontFamily: "monospace",
20
      fontSize: theme.textTheme.body1.fontSize * 0.85
21
    ),
22 23 24 25 26 27
    h1: theme.textTheme.headline,
    h2: theme.textTheme.title,
    h3: theme.textTheme.subhead,
    h4: theme.textTheme.body2,
    h5: theme.textTheme.body2,
    h6: theme.textTheme.body2,
28 29
    em: new TextStyle(fontStyle: FontStyle.italic),
    strong: new TextStyle(fontWeight: FontWeight.bold),
30
    blockquote: theme.textTheme.body1,
31 32 33 34 35
    blockSpacing: 8.0,
    listIndent: 32.0,
    blockquotePadding: 8.0,
    blockquoteDecoration: new BoxDecoration(
      backgroundColor: Colors.blue[100],
36
      borderRadius: new BorderRadius.circular(2.0)
37 38 39 40
    ),
    codeblockPadding: 8.0,
    codeblockDecoration: new BoxDecoration(
      backgroundColor: Colors.grey[100],
41
      borderRadius: new BorderRadius.circular(2.0)
42 43 44 45 46 47 48 49
    )
  );

  /// Creates a [MarkdownStyle] from the [TextStyle]s in the provided [theme].
  /// This style uses larger fonts for the headings than in
  /// [MarkdownStyle.defaultFromTheme].
  MarkdownStyle.largeFromTheme(ThemeData theme) : super (
    a: new TextStyle(color: Colors.blue[500]),
50
    p: theme.textTheme.body1,
51 52 53
    code: new TextStyle(
      color: Colors.grey[700],
      fontFamily: "monospace",
54
      fontSize: theme.textTheme.body1.fontSize * 0.85
55
    ),
56 57 58 59 60 61
    h1: theme.textTheme.display3,
    h2: theme.textTheme.display2,
    h3: theme.textTheme.display1,
    h4: theme.textTheme.headline,
    h5: theme.textTheme.title,
    h6: theme.textTheme.subhead,
62 63
    em: new TextStyle(fontStyle: FontStyle.italic),
    strong: new TextStyle(fontWeight: FontWeight.bold),
64
    blockquote: theme.textTheme.body1,
65 66 67 68 69
    blockSpacing: 8.0,
    listIndent: 32.0,
    blockquotePadding: 8.0,
    blockquoteDecoration: new BoxDecoration(
      backgroundColor: Colors.blue[100],
70
      borderRadius: new BorderRadius.circular(2.0)
71 72 73 74
    ),
    codeblockPadding: 8.0,
    codeblockDecoration: new BoxDecoration(
      backgroundColor: Colors.grey[100],
75
      borderRadius: new BorderRadius.circular(2.0)
76 77 78
    )
  );
}