Giter Club home page Giter Club logo

zh3w4ng / code_block Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mayursmahajan/code_block

0.0 0.0 0.0 1.06 MB

Code Block is a feature that allows you to write and display code snippets within your notes taken in the AppFlowy Editor. It provides a distinct format for code, using a monospaced font and syntax highlighting to enhance readability.

Home Page: https://pub.dev/packages/appflowy_code_block

License: Other

C++ 13.41% C 0.80% Objective-C 0.02% Kotlin 0.07% Dart 72.70% Swift 1.25% HTML 1.04% CMake 10.71%

code_block's Introduction

Our Goal

The goal of this project is to develop a Code Block in Flutter as a standalone package that AppFlowy and other Flutter applications can use. Code Block is a feature that allows you to write and display code snippets.

Features

Supported

  • Syntax Highlighting
  • Multiple Programming Language Support
  • Copy All Code
  • Paste Multiple lines of code
  • Export code
  • Import code
  • Cool Dark and Light Theme

Future Scope

  • Copy the entire Code Block
  • Line numbering
  • Auto-Indentation

Getting started

To use this package you need a project with AppFlowy Editor.

Usage

  1. Import the package:
import 'package:code_block/code_block.dart';
  1. Add Codeblock item to Selection Menu Items of AppFlowyEditor:
late final List<SelectionMenuItem> slashMenuItems = [
    ...standardSelectionMenuItems,
    codeBlockItem,
];
  1. Add Codeblock shortcuts to AppFlowy Editor Shortcuts:
List<CharacterShortcutEvent> get characterShortcutEvents => [
        // code block
        ...codeBlockCharacterEvents,

        // customize the slash menu command
        customSlashCommand(
          slashMenuItems,
        ),

        ...standardCharacterShortcutEvents
          ..removeWhere(
            (element) => element == slashCommand,
          ), // remove the default slash command.
      ];

  final List<CommandShortcutEvent> commandShortcutEvents = [
    ...codeBlockCommandEvents,
    ...standardCommandShortcutEvents,
  ];

It is important that you customize the slash menu command, this way you will be able to add Codeblock Item to the Selection Menu Items.

  1. Add CodeblockComponentBuilder to AppFlowy Editor's Block Component Builder Map.
final customBlockComponentBuilderMap = {
    CodeBlockKeys.type: CodeBlockComponentBuilder(
      editorState: editorState,
    ),
  };

  final builders = {
    ...standardBlockComponentBuilderMap,
    ...customBlockComponentBuilderMap,
  };
  1. Make sure you pass the shortcuts and blockComponentBuilderMap to AppFlowyEditor class.
// gets the block component builder map from a method
blockComponentBuilders = customBlockComponentBuilderMap();

AppFlowyEditor(
      editorState: editorState,
      autoFocus: true,
      characterShortcutEvents: characterShortcutEvents,
      commandShortcutEvents: commandShortcutEvents,
      blockComponentBuilders: blockComponentBuilders,
    );
  1. That's it, check out your codeblock in action by pressing the slash menu in your editor page and selecting the Codeblock option.

Additional information

Find out more about this here: https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/appflowy-mentorship-program/mentorship-2022/mentee-projects/code-block

Acknowledgements

code_block's People

Contributors

mayursmahajan avatar a-wallen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.