3

我目前正在尝试使 codemirror 和 summernote 工作,我已经按照在线教程进行操作,但文件依赖项似乎存在问题。我的代码是。我已经从 Summernote 的示例页面中获取了在线文件 url,所以它应该可以工作。

<!DOCTYPE html>
<html lang="en">


<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">

<title>Code editor</title>

<!-- Bootstrap core CSS -->
<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/font-awesome.css" rel="stylesheet"/>
<link href="css/summernote.css" rel="stylesheet">


  <link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/codemirror.min.css" />
  <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/theme/monokai.min.css">


<!-- Add custom CSS here -->

</head>

<body>
<div class="row">
  <br />
  <div class="container">
    <div class="col-lg-12">
      <form action="">

          <div class="form-group">
            <label for="">Descriptions</label>
            <textarea id="description" rows="10" class="form-control"></textarea>
          </div>  

      </form>    

    </div>

</div>  


</div>


<!-- /.end Footer -->

<!-- /.end container -->

<!-- JavaScript -->
<script src="js/jquery-1.10.2.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/summernote.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/codemirror.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/mode/xml/xml.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/codemirror/2.36.0/formatting.min.js"></script>


<script type="text/javascript">

$(document).ready(function(){
    $('#description').summernote({
       height: 400,
       codemirror: {
          theme:'monokai'
       }
    });
});





</script>

</body>

</html>

任何帮助将不胜感激....谢谢

4

2 回答 2

3

请参阅以下代码片段,它对我来说非常好。

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> 
  <title>summernote</title>
  <!-- include jquery -->
  <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> 

  <!-- include libraries BS3 -->
  <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" />
  <script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
  <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" />

  <!-- include codemirror (codemirror.css, codemirror.js, xml.js, formatting.js)-->
  <link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/codemirror.min.css" />
  <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/theme/blackboard.min.css">
  <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/theme/monokai.min.css">
  <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/codemirror.js"></script>
  <script src="http://cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/mode/xml/xml.min.js"></script>
  <script src="http://cdnjs.cloudflare.com/ajax/libs/codemirror/2.36.0/formatting.min.js"></script>

  <!-- include summernote -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.6.1/summernote.css">
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.6.1/summernote.js"></script>

  <script type="text/javascript">
    $(document).ready(function() {
      $('.summernote').summernote({
        height: 200,
        tabsize: 2,
        codemirror: {
          theme: 'monokai'
        }
      });
    });
  </script>
</head>
<body>
<textarea class="summernote"><p>Seasons <b>coming up</b></p></textarea>
</body>
</html>

然后将 cdn url 指向文件所在的本地文件系统 url。

于 2015-03-09T18:30:58.677 回答
0

使用 prettifyHtml: false 禁用 Summernote 格式化代码

$scope.summernoteOptions = {
  height: 690,
  focus: true,
  prettifyHtml: false,
  codemirror: { 
    theme: 'default',
    mode: "text/html",
    lineNumbers: true,
    tabMode: 'indent'
  }
};
于 2015-07-09T13:29:46.093 回答